if even/odd statement
19 ビュー (過去 30 日間)
古いコメントを表示
Hi, I have to write a code that doubles all odd numbers, and square all even numbers from 1 to 100. Can some1 please help me out.
0 件のコメント
採用された回答
Matt Fig
2011 年 3 月 30 日
Where are you stuck? What have you tried?
.
EDIT In response to your comment...
IF statements don't select out portions of an array like that. You will need an index to do that. Here are some clues, copy and paste into MATLAB:
x = 1:10
idx = mod(x,2)==1 % This is a logical index.
x(idx)
x(~idx)
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!