To compare to matrices element by element
65 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Pradheep S
le 21 Juil 2021
Commenté : Walter Roberson
le 21 Juil 2021
i have matrix A= [ 1 2 2 , 4 5 6] and matrix B = [ 1 2 3 , 2 3 4 ] . want to caompare element by element martix operators and any one element or all element in A if lessthan B should return matrix A is lesser .
1 commentaire
Réponse acceptée
Mudit Chaturvedi
le 21 Juil 2021
Hello!
I understand you are trying to compare two matrices element by element and return "matrix A is lesser" if any element in A is lesser than its corresponding element in B.
One of the ways to do this is to create a matrix C containing the maximum of A and B (element by element) and then checking if this new matrix is same as A or not.
C = max(A,B); %contains the max value out of A and B at each index
isequal(A,C); %returns true if A and C are equal else false
2 commentaires
Walter Roberson
le 21 Juil 2021
if isequal(A, C)
one_function()
else
different_function()
end
Voir également
Catégories
En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!