Azzera filtri
Azzera filtri

Size of each cell

2 visualizzazioni (ultimi 30 giorni)
Yro
Yro il 27 Dic 2020
Risposto: Jan il 27 Dic 2020
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.

Risposte (2)

Matt J
Matt J il 27 Dic 2020
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 il 27 Dic 2020
"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.

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by