How can I compare among three matrices ?

조회 수: 3 (최근 30일)
omar th
omar th 2022년 11월 8일
댓글: omar th 2022년 12월 7일
If I have 3 matrices for example
A = [10;26;30];
B = [12;25;35];
C = [15;29;9];
How can I compare among them to find each matrix that have the minimum value compared to other matrices to get matrices in this form
Anew = [1;0;0];
Bnew=[0;1;0];
Cnew=[0;0;1];
Thanks in advance

채택된 답변

Voss
Voss 2022년 11월 8일
A = [10;26;30];
B = [12;25;35];
C = [15;29;9];
M = [A B C];
Mnew = M == min(M,[],2)
Mnew = 3×3 logical array
1 0 0 0 1 0 0 0 1
  댓글 수: 3
Voss
Voss 2022년 11월 8일
"I want to compare each element with element of other matrices that located at the same locations."
That's what min does in this case.
A = [10;0;0;26;0;0;30];
B = [12;0;0;25;0;0;35];
C = [15;0;0;29;0;0;9];
M = [A B C];
Mnew = M == min(M,[],2) & M ~= 0
Mnew = 7×3 logical array
1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1
omar th
omar th 2022년 12월 7일
Thank you so much for your response

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by