Finding how mych values contain a specific number in a matrix
Mostrar comentarios más antiguos
I built the next matrix:
A=rand(100, 100)
I need to find how much values contain '3' in the first four digits. I would like to know how to do that.
Respuesta aceptada
Más respuestas (1)
David Fletcher
el 20 de Abr. de 2018
Editada: David Fletcher
el 20 de Abr. de 2018
Whilst I can admire the brevity of Walter's code, I might be inclined to use a more 'conventional' alternative
A=rand(100, 100);
extract=A;
count=0;
for iter=1:4
%Prepare integer value for examination
extract=extract*10;
%remove fractional part
intVals=floor(extract);
%running total of '3's in each column
count=count+sum(intVals==3);
%subtract integer portion ready for next loop
extract=extract-intVals;
%Remove numbers where 3 has been found
extract(intVals==3)=0;
end
total=sum(count);
Categorías
Más información sobre Develop Apps Using App Designer en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!