フィルターのクリア

find if there are more then 10 consecutive NaN values

1 回表示 (過去 30 日間)
Oliver Kumar
Oliver Kumar 2016 年 4 月 4 日
コメント済み: Image Analyst 2018 年 11 月 16 日
Hello
I have a 170 x 1 matrix. Whicht contains 1 and 0 values. 1 is for NaN. I have 170 of this matrices. Is there a way how i can find only the matrices which contain more the 10 consecutive NaN values?
For example I have the following:
A = [ 0 0 1 1 1 1 1 1 1 1 1 1 1 0]
B = [ 1 1 1 1 0 0 1 1 0 1 1 1 1 1]
Now I need a code that gives the solution A, so I now in A are more the 10 consecutive NaN values.
Thanks for your help. Oliver

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 4 日
編集済み: Azzi Abdelmalek 2016 年 4 月 4 日
A = [ 0 0 1 1 1 1 1 1 1 1 1 1 1 0]
ii=strfind([0 A 0],[0 1])
jj=strfind([0 A 0],[1 0])
idx=max(jj-ii)
  4 件のコメント
Oliver Kumar
Oliver Kumar 2016 年 4 月 6 日
Thanks mate
Image Analyst
Image Analyst 2016 年 4 月 6 日
Why 12????

サインインしてコメントする。

その他の回答 (3 件)

Image Analyst
Image Analyst 2016 年 4 月 6 日
Another 2 line solution:
% Create sample data:
A = [ 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0]
% Measure the lengths of each "run" of ones:
measurements = regionprops(logical(A), 'Area');
theLengths = [measurements.Area]

Andrei Bobrov
Andrei Bobrov 2016 年 4 月 5 日
i1 = find(diff([0 A 0]) == 1);
out = i1(find(diff([0 A 0]) == -1) - i1 > 10);

Prashant Dwivedi
Prashant Dwivedi 2018 年 11 月 16 日
Hello, My problem is similer .
I wantedt to consicutive non NaN values . I tried
regionprops for ~isnan.
It does not work .
Any help will appreciated .
Thank you.
  3 件のコメント
Prashant Dwivedi
Prashant Dwivedi 2018 年 11 月 16 日
編集済み: Prashant Dwivedi 2018 年 11 月 16 日
I tried like this :-
clear all
A = [ 2 5 6 2 nan nan nan 3 4 3 5 5 3 nan nan 2 2 3 4 5 5 nan 2 4 nan 4 5 5 6]
% Create sample data:
% Measure the lengths of each "run" of ones:
Mnan = regionprops(logical(A), 'Area');
theLengths = [Mnan.Area];
% Measure the lengths of each "run" of ones:
Mval = regionprops(logical(~isnan(A)), 'Area');
theLengths = [Mval.Area];
knan = length(Mnan)
kval = length(Mval)
But it gives error
Error using logical
NaN's cannot be converted to logicals.
Error in test (line 7)
Mnan = regionprops(logical(A), 'Area');
Image Analyst
Image Analyst 2018 年 11 月 16 日
Of course. And why didn't you do it like I suggested?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumeric Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by