WHY THIS SIMPLE CODE IS NOT WORKING? please help
1 view (last 30 days)
Show older comments
Md Abu Hemjal
on 30 Oct 2017
Commented: Guillaume
on 30 Oct 2017
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 Comment
Guillaume
on 30 Oct 2017
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;
Accepted Answer
Roger Stafford
on 30 Oct 2017
This code ought to work. Perhaps you have a variable somewhere in your system named ‘mod’. That would mess things up.
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!