replace matrix A with the values of another matrix B

조회 수: 1 (최근 30일)
Elysi Cochin
Elysi Cochin 2022년 5월 15일
편집: Dyuman Joshi 2022년 5월 15일
Having a matrix A as attached, how to replace all those 1 in A with the values in matrix B, so that i get a new matrix as newA
A(:,:,1) =
0 0 1
0 1 0
0 1 1
A(:,:,2) =
1 0 0
0 0 0
0 0 0
A(:,:,3) =
0 1 0
1 0 1
1 0 0
B = [6 1 5; 2 6 7; 4 6 9];
B =
6 1 5
2 6 7
4 6 9
newA(:,:,1) =
0 0 5
0 6 0
0 6 9
newA(:,:,2) =
6 0 0
0 0 0
0 0 0
newA(:,:,3) =
0 1 0
2 0 7
4 0 0

채택된 답변

Bruno Luong
Bruno Luong 2022년 5월 15일
편집: Bruno Luong 2022년 5월 15일
A= cat(3, [ 0 0 1;
0 1 0;
0 1 1], ...
[1 0 0,
0 0 0;
0 0 0], ...
[0 1 0;
1 0 1;
1 0 0 ]);
B = [6 1 5; 2 6 7; 4 6 9];
A.*B
ans =
ans(:,:,1) = 0 0 5 0 6 0 0 6 9 ans(:,:,2) = 6 0 0 0 0 0 0 0 0 ans(:,:,3) = 0 1 0 2 0 7 4 0 0

추가 답변 (1개)

Dyuman Joshi
Dyuman Joshi 2022년 5월 15일
편집: Dyuman Joshi 2022년 5월 15일
A(:,:,1) = [0 0 1; 0 1 0; 0 1 1];
A(:,:,2) = [1 0 0; 0 0 0; 0 0 0];
A(:,:,3) = [0 1 0; 1 0 1; 1 0 0];
B = [6 1 5; 2 6 7; 4 6 9];
newA=A.*B
newA =
newA(:,:,1) = 0 0 5 0 6 0 0 6 9 newA(:,:,2) = 6 0 0 0 0 0 0 0 0 newA(:,:,3) = 0 1 0 2 0 7 4 0 0

카테고리

Help CenterFile Exchange에서 Data Types에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by