interp1 issue - resampling

10 ビュー (過去 30 日間)
Andra Topan
Andra Topan 2022 年 11 月 4 日
コメント済み: Star Strider 2022 年 11 月 4 日
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!

採用された回答

Star Strider
Star Strider 2022 年 11 月 4 日
編集済み: Star Strider 2022 年 11 月 4 日
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 件のコメント
Andra Topan
Andra Topan 2022 年 11 月 4 日
Brilliant! Thank you so much!
Star Strider
Star Strider 2022 年 11 月 4 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by