WHY THIS SIMPLE CODE IS NOT WORKING? please help

1 回表示 (過去 30 日間)
Md Abu Hemjal
Md Abu Hemjal 2017 年 10 月 30 日
コメント済み: Guillaume 2017 年 10 月 30 日
r= 1:10;
s= zeros(1,10);
for t=1:10
if mod(r(t),2) == 0
s(t)=1;
else s(t)=0;
end
end
  1 件のコメント
Guillaume
Guillaume 2017 年 10 月 30 日
What makes you think it is not working? The code produces a result. If that is not the result you wanted, how are we supposed to know what that is?
Note that a much simpler version of that code is:
r = 1:10;
s = mod(r, 2) == 0;

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

採用された回答

Roger Stafford
Roger Stafford 2017 年 10 月 30 日
This code ought to work. Perhaps you have a variable somewhere in your system named ‘mod’. That would mess things up.

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