Read vector until last value, or NANs start

조회 수: 18 (최근 30일)
David Pesetsky
David Pesetsky 2018년 7월 8일
댓글: David Pesetsky 2018년 7월 8일
I have a vector array with an unknown number of entries. Either it will end nicely with the last entry being a number, or nans will start populating. I just need the index of the last actual number, not knowing if there's a next entry, or if the next is a nan.
Can you help?
Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 8일
lastidx = find(isnan(YourVector),1) - 1;
if isempty(lastidx); lastidx = length(YourVector); end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by