Effacer les filtres
Effacer les filtres

How to compare elements of two vectors in MATLAB ?

9 vues (au cours des 30 derniers jours)
charu shree
charu shree le 4 Avr 2023
Commenté : charu shree le 4 Avr 2023
Hello all, I want to compare elements of two vectors of dimension 2 x 8 but without using for loop.
Any help in this regard will be highly appreciated.

Réponse acceptée

Torsten
Torsten le 4 Avr 2023
Déplacé(e) : Torsten le 4 Avr 2023
A = [1 2; 3 4];
B = [1 4; 3 5];
sum(A(:)~=B(:))
ans = 2

Plus de réponses (1)

James Tursa
James Tursa le 4 Avr 2023
Compare for what purpose? E.g., these statements will compare them:
isequal(v1,v2) % are they equal
v1 == v2 % matrix of individual element comparisons
... and others
Unless you tell us what you intend to do with the comparison it is hard to advise you which method would apply.
  1 commentaire
charu shree
charu shree le 4 Avr 2023
Thank you so much for your answer....
Basically I want to find out how many elements are different between the two vectors.
For e.g., in 2 x 8 vector there are 16 elements and so out of these 16 elements between the two vectors how many are different.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements 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!

Translated by