How to operate block matrices?

조회 수: 13 (최근 30일)
Noemi ZM
Noemi ZM 2022년 10월 7일
댓글: Noemi ZM 2022년 10월 7일
I'd like to operate matrix in which each element is composed by two numbers. For instance,
If I have a matrix B=[1,2; 3,4] for instance, I'd like to have
Someone have some idea?
Thank you!

채택된 답변

Rik
Rik 2022년 10월 7일
Perhaps a function like pagemtimes does what you need.
You will have to store your matrix as a 3-D matrix. Even if pagemtimes is not what you want, that will make it easier to write a loop to apply the operation you do want.
  댓글 수: 2
Noemi ZM
Noemi ZM 2022년 10월 7일
Thank you!!
Image Analyst
Image Analyst 2022년 10월 7일
Can you explain exactly what was multiplied by what, and summed, to get the output matrixes?

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

추가 답변 (1개)

Paul
Paul 2022년 10월 7일
One can always store block matrices in cell arrays and then roll code to implement the block matrix algebra. Maybe there is a submittal on the FEX for a block matrix class?
A = {[1 2] , [3 4]; [3 5] , [4 2]};
B = {1 , 2; 3, 4};
C = blockmtimes(B,A)
C = 2×2 cell array
{[ 7 12]} {[ 11 8]} {[15 26]} {[25 20]}
function C = blockmtimes(A,B)
[m,n] = size(A);
[n,s] = size(B);
for ii = 1:m
for jj = 1:n
C{ii,jj} = zeros(size(A{ii,jj},1),size(B{ii,jj},2));
for kk = 1:n
C{ii,jj} = C{ii,jj} + A{ii,kk}*B{kk,jj};
end
end
end
end
  댓글 수: 1
Noemi ZM
Noemi ZM 2022년 10월 7일
Great idea, thank you!

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

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by