if loop on array
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (1)
KSSV
le 7 Fév 2022
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 commentaires
KSSV
le 7 Fév 2022
@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
le 7 Fév 2022
Any example data?
ali hassan
le 10 Fév 2022
ali hassan
le 10 Fév 2022
Catégories
En savoir plus sur Matrices and Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
