Interpolating function to make two arrays synchronise

16 ビュー (過去 30 日間)
Tom Edwards
Tom Edwards 2020 年 11 月 5 日
コメント済み: Tom Edwards 2020 年 11 月 8 日
I have an array of 101 values between 0 and 600 called Depth and another called Init_Density with 101 values between 350 - 900. Each data point corresponds to a layer so they can be plotted together and match up, some layers are thicker or thinner than others which is why we have this non regular synchronising between density and depth. I want to interpolate both arrays so I have 600 values in each that can still match up, I have tried messing around with the interp1 function but it keeps giving me NaN values and I'm not sure what I'm doing wrong, nor how to correct it.
Heres my code, I've written the variables up just as you'd see them in the workspace, I don't want to type out 101 numbers but the Depth variable
Init_Density (101 x 1 double)
Depth (101 x 1 double)
x = Init_Density(1:end);
y = Depth;
ran = 1:1:600;
xi = interp1(x,Depth,ran)';

採用された回答

KSSV
KSSV 2020 年 11 月 5 日
編集済み: KSSV 2020 年 11 月 5 日
x = Init_Density(1:end);
y = Depth;
xi = linspace(min(x),max(x),600);
yi = interp1(x,y,xi);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by