フィルターのクリア

Size of each cell

2 ビュー (過去 30 日間)
Yro
Yro 2020 年 12 月 27 日
回答済み: Jan 2020 年 12 月 27 日
I need to know the size of each cell based on the following code:
ARRAY = randi(20,20,2);
for i = 1:length(ARRAY)
find_fcn1{i,:} = find(ARRAY(:,1)==(ARRAY(i,1) + 1));
find_fcn2{i,:} = find(ARRAY(:,2)==(ARRAY(i,2) + 1));
end
if lenght('of any cell in find_fcn1' >= 3) || lenght('of any cell in find_fcn2' >= 3)
'do something'
else
'do something'
end
I tried using cellfun but it doesn't work because I generate another array.
Thanks in advance.

回答 (2 件)

Matt J
Matt J 2020 年 12 月 27 日
G1=findgroups(ARRAY(:,1));
G2=findgroups(ARRAY(:,2));
H1=histcounts(G1,1:max(G1)+1);
H2=histcounts(G2,1:max(G2)+1);
if any(H1>=3) || any(H2>=3)
%do something
else
%do something else
end

Jan
Jan 2020 年 12 月 27 日
"doesn't work" does not allow to understand, what the problem is. Please post the code you have tried and explain, what is not working as expected.
ARRAY = randi(20,20,2);
for i = 1:length(ARRAY)
find_fcn1{i,:} = find(ARRAY(:,1)==(ARRAY(i,1) + 1));
find_fcn2{i,:} = find(ARRAY(:,2)==(ARRAY(i,2) + 1));
end
ge3_fcn1 = cellfun(find_fcn1, 'length') >= 3;
ge3_fcn2 = cellfun(find_fcn2, 'length') >= 3;
match = find(ge3_fcn1 & ge3_fcn2)
Then maybe you need a for loop, not an if condition.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by