How do I do this?
X=[4 7 1 0;
3 0 6 8]
Y=[32 6 4 21;
77 89 0 2]
X(X==0)=a;
after the alteration:
X=[4 7 1 a;
3 a 6 8]
Y=[ 32 6 4 a;
77 a 0 2];

4 commentaires

Adam Danz
Adam Danz le 1 Déc 2018
Please explain in words what you'd like to do.
Image Analyst
Image Analyst le 1 Déc 2018
Modifié(e) : Image Analyst le 1 Déc 2018
Why are the non-zero locations of X changing, and why are the elements of Y changing???
Anyway, you answered your own question. You simply ignore the original X and make the assignment:
a = 99; % Whatever....
X=[3 a 4 6;
1 7 8 a]
Y=[77 a 32 0;
4 6 2 a]
There. You're done.
Hugo Matias
Hugo Matias le 1 Déc 2018
My bad, fixed it
Hugo Matias
Hugo Matias le 1 Déc 2018
I can't do it that way.
I can't do manual alterations on Y.
Y has to change exactly how X changes, automatically

Connectez-vous pour commenter.

 Réponse acceptée

Star Strider
Star Strider le 1 Déc 2018
Try this:
a = 42;
X=[4 7 1 0;
3 0 6 8]
Y=[32 6 4 21;
77 89 0 2]
Idx = X==0
X(Idx) = a
Y(Idx) = a % Use The Same Index On Both Matrices,

4 commentaires

Hugo Matias
Hugo Matias le 1 Déc 2018
Thank you sir
Star Strider
Star Strider le 1 Déc 2018
As always, my pleasure.
Hugo Matias
Hugo Matias le 1 Déc 2018
By the way, do you know how to do this one?
(sort the matrix)
before:
a=[3 9 5 7;
3 0 1 2;
11 2 0 9];
after:
a=[11 9 9 7;
5 3 3 2;
2 1 0 0;]
Yes!
a=[ 3 9 5 7;
3 0 1 2;
11 2 0 9];
a_after = reshape(sort(a(:),'descend'), 4, [])'
a_after =
11 9 9 7
5 3 3 2
2 1 0 0
My apologies for the delay. I didn’t see your comment before.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by