Help with interpol1. The grid vectors are not strictly monotonic increasing
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I have my StressAmp and FatigueLife -vectors that I am plotting and least Square fitting using the polyval and polyfit commands.
I only have data for Three Points as seen in my example. I am having trouble using interpol1 to get data within my least Square fit. I need to know the value on the x-axis when the value of y-axis is 6. What am I doing wrong and how can I fix it?
My error message is:
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1 (line 191) F = griddedInterpolant(X,V,method);
Error in MatlabHelpSNFatigue (line 30) K1=interp1(StressAmp,10.^fity,Amp1)
My matlab code is:
StressAmp=[10 6 6];
FatigueLife=[60000 264000 330000];
%Log
X=log10(StressAmp);
Y=log10(FatigueLife);
semilogx(FatigueLife,StressAmp,'*');
ylim([0 12])
set(gca,'YTick',[0:1:12])
xlabel('N')
ylabel('F')
grid on
hold on
coef=polyfit(X,Y,1)
fity=polyval(coef,X)
semilogx(10.^fity,StressAmp,'r')
%interpol
Amp1=6
K1=interp1(StressAmp,10.^fity,Amp1)
semilogx(K1,Amp1,'*r')
0 个评论
回答(1 个)
Guillaume
2015-2-26
As the error message says, for interpolating, the known x must be strictly monotonically increasing. That means no duplicate (you have two 6) and in increasing order (so 6, 10).
I don't really understand what you're trying to do. What do you expect linear interpolation to do if you have twice the same x and two different y?
3 个评论
Guillaume
2015-2-26
The problem is not with Amp1, but with StressAmp and more importantly, your understanding of linear interpolation.
linear interpolation just finds between which two known x your query point falls and then just takes the appropriate ratio of the two corresponding known y. That is, it's just:
interpolationresult = (yafter-ybefore)*(unknownx-xbefore)/(xafter-xbefore)
If you have two ybefore for a single xbefore, what do you put in the formula above?
Anyway, since you've already performed a linear regression with polyval why don't you use polyfit to find your unknown?
logK1 = polyval(coeff, log(Amp1))
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!