Trying to find Young's Modulus in a specific range. I was to plot the the data for that range, but when I try to get the slope value, it gives me NaN. I worked on the code for days and tried various methods and loopholes, but I can't seem to get it.
data = readtable('TITLE.txt','ReadVariableNames',true);
Load = data.Load(1:end);
Displacement = data.Displacement(1:end);
Strain = data.Strain(1:end);
Strain(Strain < 0.001) = NaN;
plot(Strain)
Strain(Strain > 0.003) = NaN;
plot(Strain)
p = plot(Strain, Load, '.', 'color','r')
title('Youngs Modulus','FontSize', 20);
xlabel('Strain (in/in)', 'FontSize', 15);
ylabel('Load(lbf)', 'FontSize', 15);
polyfit(Strain, Load, 1)
polyval(Strain, Load)

 채택된 답변

Jon
Jon 2020년 11월 18일
편집: Jon 2020년 11월 18일

0 개 추천

To avoid having NaN in polyfit I would use
iFit = isfinite(Strain)
c = polyfit(Strain(iFit),Load(iFit))
% ok to have NaN when calculating fitted Load
yfit = polyval(c,Strain)
By the way shouldn't Young's Moduls use Tensile Stress (Load/Area) rather than just raw load?

댓글 수: 5

Jade Pearson
Jade Pearson 2020년 11월 18일
편집: Jade Pearson 2020년 11월 18일
I had to change it to
c = polyfit(Strain(iFit),Load(iFit),1)
but it worked! Thank you
Jon
Jon 2020년 11월 18일
Sorry, for the typo. If this solves your problem when you get a chance please accept the answer so others who might have a similar issue will know an answer is available
Jon
Jon 2020년 11월 18일
Thanks - One last style point for the future, the MATLAB answers site encourages brief titles for questions with just the essense of the problem, e.g. Problem using polyfit with NaN data, and then putting the details into the body of the question. Not a big thing but it makes it a little easier to look through the questions if they have brief titles.
Jade Pearson
Jade Pearson 2020년 11월 18일
Understandable. Thank you, I will remember that.
Jon
Jon 2020년 11월 18일
Very nice - I didn't realize you could edit the original question title. Looks very clean now!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 11월 18일

댓글:

Jon
2020년 11월 18일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by