Using If statement in matlab

2 次查看(过去 30 天)
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

采纳的回答

Star Strider
Star Strider 2015-2-3
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 个评论
Aftab Ahmed Khan
Aftab Ahmed Khan 2015-2-3
Hi, Thank you. Glad to see you after soo many weeks. Take care.
Star Strider
Star Strider 2015-2-3
As always, my pleasure!
You ,too!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by