Split a vector where NaN appears

11 visualizaciones (últimos 30 días)
Marc Cowan
Marc Cowan el 5 de Abr. de 2021
Editada: dpb el 5 de Abr. de 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.

Respuesta aceptada

dpb
dpb el 5 de Abr. de 2021
Editada: dpb el 5 de Abr. de 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
>>

Más respuestas (0)

Categorías

Más información sobre NaNs en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by