interp1 issue - resampling

8 visualizzazioni (ultimi 30 giorni)
Andra Topan
Andra Topan il 4 Nov 2022
Commentato: Star Strider il 4 Nov 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!

Risposta accettata

Star Strider
Star Strider il 4 Nov 2022
Modificato: Star Strider il 4 Nov 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 Commenti
Andra Topan
Andra Topan il 4 Nov 2022
Brilliant! Thank you so much!
Star Strider
Star Strider il 4 Nov 2022
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Shifting and Sorting Matrices in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by