MATLAB Answers

Split a vector where NaN appears

조회 수: 17(최근 30일)
Marc Cowan
Marc Cowan 5 Apr 2021
편집: dpb 5 Apr 2021
I have many m*3 vectors, and for some of them, they are say, between rows p and q, (which are different for each vector) a number of NaN values in the first column. In these instances, I wish to split them into two vectors, one which contains all rows up to p, and one which contains all rows after q.
To clarify, all the NaN values appear between rows p and q, and there are no values which I wish to keep within these rows.

채택된 답변

dpb
dpb 5 Apr 2021
편집: dpb 5 Apr 2021
>> x=randn(10,1);x([4 7])=nan
x =
0.5080
0.2820
0.0335
NaN
1.1275
0.3502
NaN
0.0229
-0.2620
-1.7502
>> [pq]=[find(isnan(x),1)-1 find(isnan(x),1,'last')+1]
pq =
3 8
>>

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by