Calculating divisions in matrices

2 次查看(过去 30 天)
If I have 8 different 10*10 matrices, for example as:
Ai=rand(10,10);
Aj=rand(10,10);
Ak=rand(10,10);
Al=rand(10,10);
Bi=rand(10,10);
Bj=rand(10,10);
Bk=rand(10,10);
Bl=rand(10,10);
I want to calculate the division of them in a way that, for example for the first row I would get:
C{(1,1):(1,4)}=[(Ai/Bi)/(Aj/Bk), (Ai/Bj)/(Ak/Bl), (Ai/Bk)/(Al/Bj), (Ai/Bl)/(Aj/Bk)]; %obviously the first component would be 1/(Aj/Bk)
In a way that I would get a 4*4 cell array as the final result that each cell contains a 10*10 matrix. The indexing is basically rolling around in the order of the field i,j,k,l. So I would get the following for the second row:
C{(2,1):(2,4)}=[(Aj/Bi)/(Ak/Bl), (Aj/Bj)/(Al/Bi), (Aj/Bk)/(Ai/Bj), (Aj/Bl)/(Aj/Bk)];
I basically want to, in each row, keep the first upper denominator constant as the corresponding dimension (2:j) and roll around the order of other dimensions for the other matrices.
I didn't simplify the equations into for example (Ai*Bl/Ak*Bj) to follow the indexing protocol (i through l). Can someone please help me with writing the code for this operation? I don't want to calculate them individually, can I use a for loop or a function to do this operation? Thank you!

采纳的回答

Matt J
Matt J 2021-7-17
编辑:Matt J 2021-7-17
I don't quite understand how you sequence the combinations, but it will be something like the following:
Acell={Ai,Aj,Ak, Al};
Bcell={Bi,Bj,Bk, Bl};
p0=[1 2 3 4; 2 3 4 1; 3 4 1 2; 4 1 2 3 ].';
C=cell(4);
for i=1:4
p=p0;
p(p==i)=[];
p=reshape(p,3,4);
A=Acell(p);
B=Bcell(p);
for j=1:4
C{i,j}=(Acell{i}./B{1,j})./(A{2,j}./B{3,j});
end
end
C

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by