extract the most repeated element of a cell array

3 visualizaciones (últimos 30 días)
NA
NA el 10 de Jul. de 2019
Comentada: NA el 10 de Jul. de 2019
A={[],[18],[14],[],[],[],[14],[],[14],[18]};
I want to get most repeated element in A, (except nan).
result should be
B=14
for this reason I use this code.
B=mode(cell2mat(A));
The problem is that in some of iteration in For loop, A changes to A={[],[],[],[],[]} (A changes in each loop)
So, when I used above code, give me this warning
Warning: MODE of a 0-by-0 matrix is NaN; result was an empty matrix in
previous releases.
> In mode (line 79)
I tried to use this code, but program stops it some iteration and I need to click Enter key.
if ~isnan(cell2mat(outlier_test))
B=mode(cell2mat(A));
end
It means that if I omit above code, my program runs without any pressing on Enter key.
So, I do not know how to fix it.

Respuesta aceptada

KSSV
KSSV el 10 de Jul. de 2019
clc; clear all ;
A={[],[18],[14],[],[],[],[14],[],[14],[18]};
B = cell2mat(A)
[a,b]=hist(B,unique(B)) ;
[b' a']
  2 comentarios
KSSV
KSSV el 10 de Jul. de 2019
14 3
18 2
The above says 14 repeated for 3 times; 18 repeated for 2 times. If you want the maximum repeated one:
b(find(max(a)))
Yes thats fine.
NA
NA el 10 de Jul. de 2019
I should use this one
result=b((max(a)==a));

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by