Average lines on plot
Show older comments
I am trying to show an average line of these lines shown in the figure. Here i am plotting a stress vs strain curve with 7 different test samples. To perform my analysis i want to take the average of these lines but i am not sure what function to use.
2 Comments
Caylin Levin
on 3 Aug 2017
Do not hide indices in the names of variables. See http://www.mathworks.com/matlabcentral/answers/304528-tutorial-why-variables-should-not-be-named-dynamically-eval. If you store the data in an array instead, the handling of an arbitrary number of signals is trivial and much nicer.
Example:
% Instead of
blake_uv_h_natural_test1_force, blake_uv_h_natural_test2_force, ...
% One vector:
blake_uv_h_natural_test_force(1:7)
Then:
Stress = blake_uv_h_natural_test_force * (4.4482216 / 30);
In consequence the pice of code you have posted will be 17 lines shorter and even faster. Most of all it will be easier to debug, less prone to typos and to expand the code to more channels you would not have to change a single line of code.
By the way: I prefer shorter names, e.g. by using the CamelCase:
blakeUVhNaturalTestF
but this is a question of taste.
Answers (1)
the cyclist
on 3 Aug 2017
1 vote
4 Comments
Caylin Levin
on 3 Aug 2017
the cyclist
on 3 Aug 2017
Caylin Levin
on 3 Aug 2017
the cyclist
on 3 Aug 2017
It's pretty straightforward. It will be something like
StrainCommonPoints = 0.001:0.001:0.030;
Stress01_extrap = interp1(Strain01,Stress01,StrainCommonPoints)
and do the same for the other stress variables.
By the way, I'd just like to point out that there are also many other ways your code could be improved.
Rather than copying the same numbers (e.g. 4.4482216) over and over again, standard practice would be to define a parameter, like
StressConstant = 4.4482216;
and use that. It makes your code less error-prone, and will help you (or others) remember later what that is.
There are other things as well (like using cell arrays instead of variables named x1, x2, x3).
Categories
Find more on Stress and Strain in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!