help with if

1 回表示 (過去 30 日間)
sam arf
sam arf 2012 年 1 月 17 日
can you help me about this listing:
a=1:1:10; if (a<5) b=0; else b=1; end c=a*b; plot (a,c)
why b value is always 1? can you fix this list so the b value become 0 if a<5 and become 1 for another a?

採用された回答

Sven Schoeberichts
Sven Schoeberichts 2012 年 1 月 17 日
if you put it in a for-loop it will do as you planned:
for a=1:1:10
if a < 5
b=0;
else
b=1;
end
c(a) = a * b;
d(a) = a;
end
plot(d,c);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArgument Definitions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by