Split a vector where NaN appears

8 Ansichten (letzte 30 Tage)
Marc Cowan
Marc Cowan am 5 Apr. 2021
Bearbeitet: dpb am 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.

Akzeptierte Antwort

dpb
dpb am 5 Apr. 2021
Bearbeitet: dpb am 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
>>

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by