Finding index of closest value in an array of different dimension

조회 수: 15 (최근 30일)
Hello!
I have a large dataset of total pressure data and corresponding time in julian date. I have another dataset of different dimensions, with atmospheric pressure and time in julian date, with different observation times. My ultimate goal is to subtract atmospheric pressure at the closest time stamp from each observation of total pressure. I am aiming to do this by finding the index of the minimum difference between times, and subtracting the atmospheric pressure with that same index from the total pressure.
To find the index of the minimum difference between times, I have...
an array of times corresponding with total pressure, (2100x7647) - I call this array "x" in the below code.
an array of times corresponding with atmospheric pressure (2394x1) - I call this array "y" in the below code.
My matlab skills are poor to fair, but this is what I have so far:
[mlength mwidth] = size(y);
olength = length(x);
for ii = 1:mlength
for jj = 1:mwidth
for kk = 1:olength
[index(kk)] = min(abs(x(ii,jj)-y(kk,2)));
end
end
end
This is not working for me because
  1. it is VERY inefficient
  2. it is producing an array with different dimensions than I expected it to
  3. the array is not filled with indeces corresponding to matching times but rather filled with times.
If someone could help me figure out what I am doing wrong I would be very grateful!
Thank you,
Rae

채택된 답변

Star Strider
Star Strider 2019년 12월 6일
I am not certain that I understand what you want to do.
If you want to use the discrete timestamps, the ismembertol function might be worth trying.
An alternative approach is to interpolate, for example with the interp1 function.
  댓글 수: 2
Rae Taylor-Burns
Rae Taylor-Burns 2020년 1월 29일
Thanks! interp1 was what i needed. Sorry for the delayed response and thanks for your help!
Star Strider
Star Strider 2020년 1월 30일
As always, my pleasure!
MATLAB Answers was down for at least 8 hours today (at least for me), so I am only now seeing this.

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

추가 답변 (0개)

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by