WHY THIS SIMPLE CODE IS NOT WORKING? please help

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 comentario

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;

Iniciar sesión para comentar.

 Respuesta aceptada

Roger Stafford
Roger Stafford el 30 de Oct. de 2017

0 votos

This code ought to work. Perhaps you have a variable somewhere in your system named ‘mod’. That would mess things up.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 30 de Oct. de 2017

Comentada:

el 30 de Oct. de 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by