Obtain logical vector for the position of the values located above and below NaNs
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Konstantinos Tsitsilonis
il 16 Giu 2018
Risposto: Ameer Hamza
il 16 Giu 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 Commenti
Risposta accettata
Ameer Hamza
il 16 Giu 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su NaNs in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!