How to make a matrix mirror another?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hugo Matias
am 1 Dez. 2018
Kommentiert: Star Strider
am 2 Dez. 2018
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 Kommentare
Akzeptierte Antwort
Star Strider
am 1 Dez. 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 Kommentare
Star Strider
am 2 Dez. 2018
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.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!