필터 지우기
필터 지우기

How to make a matrix mirror another?

조회 수: 4 (최근 30일)
Hugo Matias
Hugo Matias 2018년 12월 1일
댓글: Star Strider 2018년 12월 2일
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
Hugo Matias
Hugo Matias 2018년 12월 1일
My bad, fixed it
Hugo Matias
Hugo Matias 2018년 12월 1일
I can't do it that way.
I can't do manual alterations on Y.
Y has to change exactly how X changes, automatically

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2018년 12월 1일
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
Hugo Matias
Hugo Matias 2018년 12월 1일
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;]
Star Strider
Star Strider 2018년 12월 2일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Eigenvalues and Eigenvectors에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by