Obtain logical vector for the position of the values located above and below NaNs
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Konstantinos Tsitsilonis
el 16 de Jun. de 2018
Respondida: Ameer Hamza
el 16 de Jun. de 2018
Hi guys,
I have a pretty simple question. I would like to obtain the logical vector indicating the indices of numerical values that lie above and below NaNs. This way, my goal would be to construct a logical vector that gives me the position of a NaN only if it has a numerical value on top and below it.
For example:
xq = [5 3 nan 2 8 nan 3 3 2 8 nan nan nan 4 nan ]' ;
The output I would like to get is
idx = [0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 ]' ;
Thanks for your answer in advance,
KMT.
0 comentarios
Respuesta aceptada
Ameer Hamza
el 16 de Jun. de 2018
Try this
xq = [5 3 nan 2 8 nan 3 3 2 8 nan nan nan 4 nan]';
nanIndex = isnan(xq);
requiredIndex = strfind(nanIndex', [0 1 0])+1; % first argument must be row vector
This will give you numeric index. To get the logical vector, add the following lines to this code
requiredResultLogical = false(size(xq));
requiredResultLogical(requiredIndex) = true;
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre NaNs en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!