matlab: count the number of elements in a matrix

Three statistical methods:

A=ceil(rand(100,100)*10);
a = 5 ;
 % first
sum(A(:) == a);
 % second
length(find(A == a);
 % third
logical=(A=a);
sum(logical(:));

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324578706&siteId=291194637