필터 지우기
필터 지우기

If I let A, B, and C be 2x2 matrices, is it possible for me to assign a label to each matrix element in matrix C where C = A*B?

조회 수: 2 (최근 30일)
Let A, B, and C be separate 2x2 matrices. In this case, we let matrix C = A*B.
  댓글 수: 4
Sam Chak
Sam Chak 2022년 6월 4일
Can you give an example? Like...
A = [1 2; 3 4]
A =
1 2
3 4
B = [5 6; 7 8]
B =
5 6
7 8
C = A*B
C =
19 22
43 50
det(C)
ans = 4.0000
Craig Egan Allistair Tan
Craig Egan Allistair Tan 2022년 6월 4일
Something like in matrix C, we let C11 = 19, C12 = 22, C21 = 43, and C22 = 50.

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

채택된 답변

Matt J
Matt J 2022년 6월 4일
편집: Matt J 2022년 6월 4일
I'm talking about assigning a variable to each matrix element
One way,
A=rand(2);
B=rand(2);
C=A*B,
C = 2×2
0.2598 0.3906 0.5097 0.7454
tmp=num2cell(C);
[c1,c2,c3,c4]=deal(tmp{:})
c1 = 0.2598
c2 = 0.5097
c3 = 0.3906
c4 = 0.7454
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 6월 4일
Note that changing the c* variables will not change the matrix. The above code does not define the c* variables as being "references" to the array elements, only as copies of the array elements. There is no way to create references to individual elements of a numeric array.

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

추가 답변 (1개)

Matt J
Matt J 2022년 6월 4일
편집: Matt J 2022년 6월 4일
The attached class might be what you are looking for, if all you want to do are the operations C=A*B. To understand what it's doing, you need to get familiar with handle classes.
A=myclass(rand(2)), B=myclass(rand(2)),
A =
0.7690 0.7854 0.5502 0.8403
B =
0.6974 0.3235 0.7494 0.6334
C=A*B
C =
1.1248 0.7462 1.0134 0.7102
c12=C(1,2)
c12 =
0.7462
C(1,2)=3
C =
1.1248 3.0000 1.0134 0.7102
c12
c12 =
3

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by