if even/odd statement
21 次查看(过去 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!