Effacer les filtres
Effacer les filtres

Size of each cell

2 vues (au cours des 30 derniers jours)
Yro
Yro le 27 Déc 2020
Réponse apportée : Jan le 27 Déc 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.

Réponses (2)

Matt J
Matt J le 27 Déc 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 le 27 Déc 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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by