precision of function: UNIQUE
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
dear all,
I am trying to use interp1 for a simple matrix, the first row has X coordinates and the second row Y coordinates from experimental data.
The problem now is that X coords have precision 0.0000 so the function interp1 faces problem giving the error below:
Error using griddedInterpolant
The grid vectors are not strictly monotonic increasing.
very nice, common one. i used the function unique to 'clean' the X-values but i think that it cannot recognize the difference up to specific precision so i get the same values back.
Does anyone know if i can choose the precision or any other trick for this one?
Thank you
0 comentarios
Respuestas (2)
Star Strider
el 9 de Dic. de 2022
That they are not monotonically increasing is not the same as their not being unique. That is a different problem.
If you know the approximate value you want to interpolate, do something like this —
x = 0:0.1:2*pi;
y = sin(x);
yq = 0.5; % Determine X-Values For This Y-Value
idxv = find(diff(sign(y-yq)));
for k = 1:numel(idxv)
idxrng = max(1,idxv(k)-1) : min(numel(x),idxv(k)+1);
xq(k) = interp1(y(idxrng), x(idxrng), yq);
end
xq % X-Values Where 'y = yq'
figure
plot(x, y)
hold on
plot(xq, ones(size(xq))*yq, 'rs')
hold off
grid
.
0 comentarios
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
