How to find position of something
古いコメントを表示
Hi, I am having a problem with part of my homework. I have a column with numbers and NaN-s. If I have 5 or more NaN-s in a row I need to know place/position where NaN start (j) and end (i) ( in all column). For example 7 6 5 NaN NaN NaN NaN NaN NaN 9 7
j=4 i=9 Thanks you very much :)
採用された回答
その他の回答 (2 件)
Mohammad Monfared
2013 年 12 月 7 日
Suppose you have a column or row vector named 'A',
find(isnan(A))
4 件のコメント
Martina
2013 年 12 月 7 日
Mohammad Monfared
2013 年 12 月 7 日
編集済み: Mohammad Monfared
2013 年 12 月 7 日
If there are just one group of NaNs:
j=find(isnan(A),1,'first')
i=find(isnan(A),1,'last')
Is that your case?
Martina
2013 年 12 月 7 日
Mohammad Monfared
2013 年 12 月 7 日
It's not a straightforward simple line job, to me. One trick is to use the diff(isnan(A)) to find the boundaries of NaN groups and one more 'diff' to get the length of each group. Then a loop might be used afterward. Think about it (since it is a homework ;) ) a bit. If no success, I'll give the answer.
Image Analyst
2013 年 12 月 7 日
編集済み: Image Analyst
2013 年 12 月 7 日
Really easy if you have the Image Processing Toolbox. Do you have that?
measurements = regionprops(isnan(vector), 'PixelIdx');
% just 2 or 3 lines more and you've got it.
By the way, you shoudl have tagged it as homework - I did this for you this time.
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!