if loop on array
이전 댓글 표시
i want to use if loop on a array. let say if i have two arrays:
a=[1 2 3 4 5]
b=[2 3 4 5 6]
now if i want to use if loop such that when any value in array 'a' is 3 and corresponding value in array 'b' is 4,it should print 'ali'.
i tried the following code but it did'nt work.
a=[3 4 3 44 3];
b=[4 3 4 34 26];
if (any(a==3) & b==4)
sprintf('ali')
end
채택된 답변
추가 답변 (1개)
KSSV
2022년 2월 7일
a=[3 4 3 44 3];
b=[4 3 4 34 26];
if (any(a==3))
idx = a == 3 ;
if any(b(idx) == 4 )
fprintf('ali\n')
end
end
댓글 수: 4
KSSV
2022년 2월 7일
@ali hassan commented: https://www.mathworks.com/matlabcentral/answers/1644540-if-loop-on-array#answer_890440
what if i want to give a range of valus? like if a has a value between 3 and 4 and corresponding value of b is between 4 and 5?
KSSV
2022년 2월 7일
Any example data?
ali hassan
2022년 2월 10일
ali hassan
2022년 2월 10일
카테고리
도움말 센터 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
