how to realize look up function in m script

hello, i have x axle table and y axle table, when i set value within the range of x, how to get the output from y, may be some interpolation and curve smoothing should used. i hope it works in m script.

8 comentarios

Mathieu NOE
Mathieu NOE el 5 de Jul. de 2024
hello
sure , you can use interpolation (with interp1 ) or you can also fit a polynomial with polyfit
wenchao zhang
wenchao zhang el 5 de Jul. de 2024
Editada: wenchao zhang el 5 de Jul. de 2024
hi,Mathieu, if i just want use simple smooting method,not consider polynominal,how to do
Star Strider
Star Strider el 5 de Jul. de 2024
The interp1 function has several method options, depending on what you want to do.
For example:
xi = 90;
yi = interp1(x, y, xi, 'linear')
yi = interp1(x, y, xi, 'pchip')
To find a value of ‘x’ that corresponds to a specific value of ‘y’, simply reverse the arguments:
yi = 90;
xi = interp1(y, x, yi, 'linear')
xi = interp1(y, x, yi, 'pchip')
Fortunately, ‘y’ appears to be a monotonically increasing function of ‘x’. If that were not the situation, it would be necessary to determine the approximate indices of the ‘x’ values where ‘y’ crossed a specific value, and then interpolate in each region in a for loop.
.
Mathieu NOE
Mathieu NOE el 5 de Jul. de 2024
if you can , share yur data and we can show you some options (if you are unsure how to proceed)
wenchao zhang
wenchao zhang el 5 de Jul. de 2024
ok, i wiil share data later.
wenchao zhang
wenchao zhang el 5 de Jul. de 2024
extreploation need consider, if input x is out of range
xi = interp1(y, x, yi, 'linear', 'extrap')
wenchao zhang
wenchao zhang el 6 de Jul. de 2024
yes,you are right.

Iniciar sesión para comentar.

 Respuesta aceptada

wenchao zhang
wenchao zhang el 5 de Jul. de 2024
Editada: Walter Roberson el 5 de Jul. de 2024
use interp1 seems ok,
x = 0:pi/4:2*pi;
v = sin(x);
xq = 0:pi/16:2*pi;
figure
vq2 = interp1(x,v,xq,'spline');
plot(x,v,'o',xq,vq2,':.');
xlim([0 2*pi]);
title('Spline Interpolation');

Más respuestas (0)

Categorías

Productos

Versión

R2018b

Preguntada:

el 5 de Jul. de 2024

Comentada:

el 6 de Jul. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by