interp1 for matrix

조회 수: 47 (최근 30일)
Heidi Hirsh
Heidi Hirsh 2019년 8월 24일
댓글: Heidi Hirsh 2019년 8월 25일
I have two velocity matrices that I want to interpolate onto a new time vector. The matrices are both 8011x60 doubles where the rows are different times and the columns are depths. Can I use interp 1 to interpolate each row onto the new time?
This is how I have it set up now (how I would use interp1 if U and V were vectors):
I took a screenshot of my workspace too if that helps.
U_new = interp1(Date,U,M1time);
V_new = interp1(Date,V,M1time);
Temp_new = interp1(Date,Temp,M1time);
  댓글 수: 2
dpb
dpb 2019년 8월 24일
Did you not try it? There's an example in the documentation precisely the usage to interpolate arrays by column to a common set of query points...
Heidi Hirsh
Heidi Hirsh 2019년 8월 25일
Hi! Thank you for pointing out the size discrepancies. I realized I had somehow reloaded an old velocity file (that was two timestamps short). Once I fixed that, interp1 worked fine the way I had written it. I apologize for appearing so idiotic. Thank you for your help :)

댓글을 달려면 로그인하십시오.

채택된 답변

darova
darova 2019년 8월 24일
You have to make the same number of rows for Date and U
U_new = interp1(Date,U,M1time);
% size(Date): 8013x1
% size(U): 8011x60
Didn't you get an error about size match?
  댓글 수: 1
Heidi Hirsh
Heidi Hirsh 2019년 8월 25일
I fixed the size issue and it ran fine. I somehow reloaded the wrong data file (2 velocity vectors shorter than time).

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2019년 8월 24일
No you should use interp2 for this. The value to look up depends on two factors, depth and time, but interp1 would only take one factor into account.
  댓글 수: 2
dpb
dpb 2019년 8월 24일
Hmmmm, Walter. I don't see what you're seeing--just that wants to interpolate onto a new time vector the two arrays. Altho I see the reference to the depth being what the columns of the array refer to I didn't see and his example code doesn't seem to want to do more than just those onto the Mitime vector.
Guess we'll find out if OP comes back... :)
Heidi Hirsh
Heidi Hirsh 2019년 8월 25일
Hi guys! Thank you for the help! I think in this case interp1 did the trick since I was only trying to interpolate over time. But I have never used interp2 before so I really appreciate that advice and I will try it on another data set I have in mind where I do need to interpolate over depth.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by