if even/odd statement
22 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Matt Fig
am 30 Mär. 2011
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)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!