Matrix syntax error question

8 vues (au cours des 30 derniers jours)
Luke Blades
Luke Blades le 18 Avr 2016
Commenté : Guillaume le 18 Avr 2016
Hello,
I have 2 matrices 500 x 500, A and B.
I want to replace all values within A which are larger than the corresponding values in B WITH the value in B. Hope that makes sense!
I've tried
A(A>B) = B
But i get the error:
"In an assignment A(I) = B, the number of elements in B and I must be the same."
Do I have my syntax wrong? The two matrices are definitely both 500 x 500.
Many thanks,
Luke Blades

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 18 Avr 2016
index=A>B;
A(index)=B(index);
  1 commentaire
Guillaume
Guillaume le 18 Avr 2016
Yes, what you're missing is a filter on B. As a one liner:
A(A > B) = B(A > B);

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Performance and Memory 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