Using If statement in matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Aftab Ahmed Khan
le 3 Fév 2015
Commenté : Star Strider
le 3 Fév 2015
Hello everyone, I have to understand this from you guys, that i am using this
for i=1:10
if (i==1)||(i==3)||(i==5)||(i==7)
end
end
which is working fine for me, but i want to do it in this way but it is not giving me the same or correct result when i do it like this. Can you guys help me with it.
for i=1:10
if i==[1,3,5,7]
end
end
0 commentaires
Réponse acceptée
Star Strider
le 3 Fév 2015
Using the any function will do what you want:
for i=1:10
if any(i==[1,3,5,7])
fprintf(1,'\ti == %d\n', i)
end
end
produces:
i == 1
i == 3
i == 5
i == 7
2 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!