Skip to content

Instantly share code, notes, and snippets.

@hmurraydavis
Last active August 29, 2015 14:00
Show Gist options
  • Save hmurraydavis/11300320 to your computer and use it in GitHub Desktop.
Save hmurraydavis/11300320 to your computer and use it in GitHub Desktop.
Calculate the elastic modulus from raw CSV separated data from instron tests
function calculateElasticModulusInstron(x,y)
%%%% Compute the elastic modulus from experamental data.
%%%% INPUT VARIABLE DEF: x=load of sample from experamental data,
%%%% y=elongation of sample from experamental data.
%%prep matlab environment:
clc; clf;
%% Define length of the slope which you want to calculate Elastic Modulus for:
lengths1 = 300:1800;
%% Select input data:
x = x(lengths1);
y = y(lengths1);
%Best fit line math:
p = polyfit(x,y,1); % p returns 2 coefficients fitting r = a_1 * x + a_2
r = p(1) .* x + p(2); % compute a new vector r that has matching datapoints in x
%% now plot both the points in y and the curve fit in r
plot(x, y, 'x'); % raw data
hold on;
plot(x, r, 'r-','LineWidth',4.3); % calculated line of best fit
hold off;
ElasticModulus=p(1) %print elastic modulus (slope)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment