I want to sum the loop result which the result is indicates the total of selected input

1 回表示 (過去 30 日間)
disp('Please vote for your candidates'); a=1; b=2; c=3; d=4;
for y=1:5
x=input('your candidates= ')
end
w = sum(a)
x = sum(b)
y = sum(c)
z = sum(d)

採用された回答

Wanbin Song
Wanbin Song 2015 年 10 月 27 日
You can code it as belows:
disp('Please vote for your candidates'); a=1; b=2; c=3; d=4;
result = [];
for y=1:5
x = input('your candidates= ');
result = [result x];
end
w = nnz(result == a)
x = nnz(result == b)
y = nnz(result == c)
z = nnz(result == d)
Using vector concatenation and nnz(number of non-zero) function.
  1 件のコメント
Muhamad Zulfikre Norsid
Muhamad Zulfikre Norsid 2015 年 10 月 27 日
Thanks Wanbin Song.. I'm really appreciated with your help.. Thanks a lot..

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

その他の回答 (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