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!