plot smoothing to get a curve

 Respuesta aceptada

Star Strider
Star Strider el 10 de Sept. de 2016

5 votos

Use the linspace function to create ‘XA’:
XA = linspace(0,5);
This creates 100 (by default) regularly-spaced elements for ‘XA’ between 0 and 5.

4 comentarios

Lila wagou
Lila wagou el 10 de Sept. de 2016
HY Star Strider, i look to the smoothing option, by Excel software it is easy to do it, what about Matlab
Star Strider
Star Strider el 10 de Sept. de 2016
Use the MATLAB interp1 function.
Example:
x = [1 3 4 5.5 7 10 15]; % Create Original Data
y = [0 3 1 -2 4 9 5]; % Create Original Data
xi = linspace(min(x), max(x), 150); % Evenly-Spaced Interpolation Vector
yi = interp1(x, y, xi, 'spline', 'extrap');
figure(1)
plot(x, y, 'bp')
hold on
plot(xi, yi, '-r')
hold off
grid
xlabel('X')
ylabel('Y')
legend('Original Data', 'Interpolation', 'Location', 'NW')
Lila wagou
Lila wagou el 10 de Sept. de 2016
dear, why 50, and it does not work with the following data:
XA = [4,8,12,14,15,15.5,16,20]
YA = [100,400,100,200,150,175,160,160]
Star Strider
Star Strider el 10 de Sept. de 2016
The choice of 50 interpolation points is simply my choice.
It does work with those data:
XA = [4,8,12,14,15,15.5,16,20];
YA = [100,400,100,200,150,175,160,160];
x = XA;
y = YA;
xi = linspace(min(x), max(x), 150); % Evenly-Spaced Interpolation Vector
yi = interp1(x, y, xi, 'spline', 'extrap');
figure(1)
plot(x, y, 'bp')
hold on
plot(xi, yi, '-r')
hold off
grid
xlabel('X')
ylabel('Y')
legend('Original Data', 'Interpolation', 'Location', 'NE')
If it produces a different result than you get with Excel, it is because the interpolation method is different. The 'spline' method I used here may be correct, and Excel may be wrong. I have no idea what Excel uses. MATLAB offers several different interpolation methods, so choose the one that is most appropriate to your data.
Preferably, if you have an appropriate mathematical model of the process that produced your data, use it, and fit it to your data, rather than using interpolation.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Preguntada:

el 10 de Sept. de 2016

Comentada:

el 10 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by