Borrar filtros
Borrar filtros

how to find the total number of ones from the given input...

1 visualización (últimos 30 días)
suppose my input is a=1,b=1,c=1,d=0... my objective is to find count the total number of ones.. how to find.. which method is good to follow

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 20 de Nov. de 2013
a=1,
b=1,
c=1,
d=0
Instead of using all these variables, you can use just one array
v=[a b c d ]
To count number of ones
no=sum(v)
  2 comentarios
Image Analyst
Image Analyst el 20 de Nov. de 2013
or sum(v==1) just in case there are any integers other than 0 and 1 in there.
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran el 20 de Nov. de 2013
Thanks image analyst and azzi...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by