Obtain logical vector for the position of the values located above and below NaNs
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Ameer Hamza
2018 年 6 月 16 日
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!