필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

If statement: if none of doubles~= X then change the value of X to the closest to X...

조회 수: 2 (최근 30일)
Wiktoria Glogowska
Wiktoria Glogowska 2019년 7월 23일
마감: MATLAB Answer Bot 2021년 8월 20일
I am designing a GUI to plot data on a user chosen time interval. I have a double 100x1 of datenum values which are not uniformly spaced. When user inputs a start time and there is no such double value I would like to have an if statement which will replace the start time with the closest there is to the inputted time. I would like to know if there is such a function ''if none such value found''? Thanks for help! (I presume isempty() doesn't work since my input is not an array and always has some values in it)

답변 (1개)

Walter Roberson
Walter Roberson 2019년 7월 23일
One step: interp1 with 'nearest'
But also very reasonable:
[~, idx] = min(abs(Times - entered_time))
Times(idx)

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by