how to count the number of different elements in two matrices

7 visualizaciones (últimos 30 días)
Suppose there are 2 matrices of double type each with same elements, assume
a = [1,0,0,0,1] and
b = [1,0,0,0,0].
Here, the nnumber of different elements is 1(i.e. the last element is different)
and finally it should give the result as, 1/5= 0.2. It means, result = no. of differet elemet / total number of element.
Kindly suggest.

Respuesta aceptada

madhan ravi
madhan ravi el 14 de Nov. de 2018
diffelements=sum(a~=b)
result=diffelements/numel(a)

Más respuestas (1)

Stephen23
Stephen23 el 15 de Nov. de 2018
Simpler:
mean(a~=b)

Categorías

Más información sobre Image Processing Toolbox 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