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일

0 개 추천

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개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2015년 2월 3일

댓글:

2015년 2월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by