Size of each cell

1 visualización (últimos 30 días)
Yro
Yro el 27 de Dic. de 2020
Respondida: Jan el 27 de Dic. de 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.

Respuestas (2)

Matt J
Matt J el 27 de Dic. de 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 el 27 de Dic. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by