如何使此程序正常运行?

h=6:2:18; %一个1*7的double
t=[18,20,22,25,30,28,24;15,19,24,28,34,32,30]; %一个2*7的double
x=6.5:2:17.5; %一个1*6的double
y=interp1(h,t,x,'spline'); %用“3次样条插值求近似值”
错误使用 interp1>reshapeAndSortXandV
LENGTH(X) 和 SIZE(V,1) 必须相同。
出错 interp1 (第 128 行)
[X,V,orig_size_v] = reshapeAndSortXandV(X,V);

 採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 11 月 21 日

1 投票

As the error states, The function interp1() expects the length of the first input to be equal to the number of rows in the second input.
To achieve that, you can transponse 't' -
h=6:2:18; %一个1*7的double
t=[18,20,22,25,30,28,24;15,19,24,28,34,32,30]; %一个2*7的double
x=6.5:2:17.5; %一个1*6的double
%Transposing t
t = transpose(t);
%Interpolation
y=interp1(h,t,x,'spline')
y = 6×2
18.5020 15.6553 20.4986 20.3355 22.5193 24.9089 26.3775 29.6383 30.2051 34.2568 26.8178 30.9594

2 件のコメント

博琰
博琰 2023 年 11 月 21 日
ohhhhhh!!!!!!Thank you! This is my MATLAB assignment, thank you so much!
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 21 日
You are welcome!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange插值 についてさらに検索

質問済み:

2023 年 11 月 21 日

コメント済み:

2023 年 11 月 21 日

Community Treasure Hunt

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

Start Hunting!