Interpolating function to make two arrays synchronise

조회 수: 14 (최근 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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by