WHY THIS SIMPLE CODE IS NOT WORKING? please help
조회 수: 1 (최근 30일)
이전 댓글 표시
r= 1:10;
s= zeros(1,10);
for t=1:10
if mod(r(t),2) == 0
s(t)=1;
else s(t)=0;
end
end
댓글 수: 1
Guillaume
2017년 10월 30일
What makes you think it is not working? The code produces a result. If that is not the result you wanted, how are we supposed to know what that is?
Note that a much simpler version of that code is:
r = 1:10;
s = mod(r, 2) == 0;
채택된 답변
Roger Stafford
2017년 10월 30일
This code ought to work. Perhaps you have a variable somewhere in your system named ‘mod’. That would mess things up.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!