필터 지우기
필터 지우기

Finding a point in data with FIND - accommodate both increasing and decreasing data

조회 수: 2 (최근 30일)
Hello, I have data that I want to find the point closest to a threshold (th=800).
1728.00 1755.00 1778.00 1738.00 1810.00 1552.00 1274.00 924.00 668.00 407.00 202.00 132.00
then I use:
idx = single(find(data >= th, 1, 'last'));
However, sometimes the data is reversed so it would be 'first'.
idx = single(find(data >= th, 1, 'first'));
How can I accommodate both scenarios?
(For info, i then use this index to seed a more accurate value)
vq1 = interp1(line(yval-1:yval+1), x(yval-1:yval+1), th,'pchip'); % Interpolate In Region
  댓글 수: 1
Jason
Jason 2018년 1월 30일
But the data is randomly alternated, and I don't want to have to go into the code each time. I think I have done it with:
diff=line-th
[~,idx] = min(abs(diff))

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

채택된 답변

Matt J
Matt J 2018년 1월 30일
[~, idx] =min(abs(data - th));

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by