if loop on array
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (1)
KSSV
el 7 de Feb. de 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 comentarios
KSSV
el 7 de Feb. de 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
el 7 de Feb. de 2022
Any example data?
ali hassan
el 10 de Feb. de 2022
ali hassan
el 10 de Feb. de 2022
Categorías
Más información sobre Matrices and Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
