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

2 ビュー (過去 30 日間)
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2013 年 11 月 20 日
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

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 11 月 20 日
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 件のコメント
Image Analyst
Image Analyst 2013 年 11 月 20 日
or sum(v==1) just in case there are any integers other than 0 and 1 in there.
Sivakumaran Chandrasekaran
Sivakumaran Chandrasekaran 2013 年 11 月 20 日
Thanks image analyst and azzi...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by