interp1 "The values of X should be distinct."

4 visualizaciones (últimos 30 días)
Volkan Yangin
Volkan Yangin el 29 de Nov. de 2015
Comentada: dpb el 29 de Nov. de 2015
Hi everbody.
I want to find the "Ne" values while "n_motor" values increase 1 by 1.
Ne=[. . . . . 1724 values]
n_motor=[. . . . . 1724 values]
for i=800:1:2455;
a=interp1(n_motor,Ne,i);
end
but matlab gives me "The values of X should be distinct." error. How can i adjust this problem?
Thanks...

Respuestas (1)

dpb
dpb el 29 de Nov. de 2015
Hmmm....mayhaps TMW has changed the error message slightly? Generally one has a doubled-value in the interpolating function -- illustrate by example:
>> x=[1 1 4]; y=sqrt(linspace(1,pi,3)); % x contains a duplicated value
>> xi=[1:0.5:4]; % the interpolant vector
>> interp1(x,y,xi)
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
Error in interp1>Interp1D (line 346)
F = griddedInterpolant(Xext,V,method);
Error in interp1 (line 241)
Vq = Interp1D(X,V,Xq,method);
>> x(2)=x(2)+eps % fix up by making a miniscule difference in the two values of x...
x =
1.0000 1.0000 4.0000
>> interp1(x,y,xi)
ans =
1.0000 1.4946 1.5502 1.6057 1.6613 1.7169 1.7725
>>
The second lets interp1 function but is such as small delta as to be nearly indistinguishable in the original vector. NB: As with most Matlab functions, interp1 is vectorized to handle multiple inputs; no need for a loop for it, anyway, unless the rest of the problem does require such...
Isn't quite the same error message but this is R2012b so don't know what more recent releases might say.
Test for
a(diff(n_motor))
If false (zero), it is the above.
  2 comentarios
Volkan Yangin
Volkan Yangin el 29 de Nov. de 2015
Editada: Volkan Yangin el 29 de Nov. de 2015
my "n_motor" values are increase and declining on operations. i think this error message originated by this problem.
for ex.
n_motor=[800 800 851 858 900 850 800 ...]
dpb
dpb el 29 de Nov. de 2015
That's got both problem of duplicated values and a double-valued functional (at least, if not more). The first issue is solvable by the technique outlined above; the latter is insolvable by interp1 alone; how is it to know which solution is to be returned for a value of 825, for example--that between the 2nd/3rd entries or the 6th/7th???
You'll have to have piecewise interpolating function and call the one desired unless the results are similar and it can be sorted and use a smoothing spline or somesuch.
OBTW, that is a difference in error handling it appears, the above generates the same error of "not strictly monotonic" here...

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by