interp1 issue - resampling

10 visualizaciones (últimos 30 días)
Andra Topan
Andra Topan el 4 de Nov. de 2022
Comentada: Star Strider el 4 de Nov. de 2022
variable1=[24.6944086885135;21.0998152063394;14.7533601994682;6.76823133654033;6.73000233602188;8.34930121372767;29.2864760248330;43.5413625307145;46.7782562150740;48.3839944347439];
auxvariable2=linspace(1.1,156.3,1569);
output=interp1(variable1(1:10,1),auxvariable2);
%
Hi. I got a question about interp1.
I have the data from variable1. I want to create 1569 new points using that data.
I don;t know the function, so I am using interp with 2 parameters.
I am expecting to get 1569 points, but I get 90 points and the rest until 1569 are NaN.
What am I getting wrong?
Thank you!

Respuesta aceptada

Star Strider
Star Strider el 4 de Nov. de 2022
Editada: Star Strider el 4 de Nov. de 2022
Try something like this —
variable1=[24.6944086885135;21.0998152063394;14.7533601994682;6.76823133654033;6.73000233602188;8.34930121372767;29.2864760248330;43.5413625307145;46.7782562150740;48.3839944347439];
v1 = 1:numel(variable1);
v2 = linspace(min(v1), max(v1), 1569);
output = interp1(v1, variable1, v2).';
szvariable1 = size(variable1)
szvariable1 = 1×2
10 1
szoutput = size(output)
szoutput = 1×2
1569 1
figure
plot(v1, variable1, '.b', 'MarkerSize',10, 'DisplayName','Original')
hold on
plot(v2, output, '.r', 'MarkerSize',0.1, 'DisplayName','Interpolated')
hold off
grid
legend('Location','best')
figure
plot(v1, variable1, '.b', 'MarkerSize',10, 'DisplayName','Original')
hold on
plot(v2, output, '.r', 'MarkerSize',0.5, 'DisplayName','Interpolated')
hold off
grid
legend('Location','best')
xlim([4.75 5.25])
EDIT — (4 Nov 2022 at 16:38)
Added second plot for clarity.
.
  2 comentarios
Andra Topan
Andra Topan el 4 de Nov. de 2022
Brilliant! Thank you so much!
Star Strider
Star Strider el 4 de Nov. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by