Problem using polyfit with NaN data

14 ビュー (過去 30 日間)
Jade Pearson
Jade Pearson 2020 年 11 月 18 日
コメント済み: Jon 2020 年 11 月 18 日
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 日
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 日
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 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by