Matrix multiplication using a for loop

I want to make matrix A using elements of matrices P1 and P2 in the following form. Is there any way to do this using a for loop. Any help would be appreciated!
A(1,:) = [P1(1,1).*P2(1,1:4) P1(1,2).*P2(1,1:4) P1(1,3).*P2(1,1:4) P1(1,4).*P2(1,1:4)]
A(2,:) = [P1(2,1).*P2(2,5:8) P1(2,2).*P2(2,5:8) P1(2,3).*P2(2,5:8) P1(2,4).*P2(2,5:8)]
A(3,:) = [P1(3,1).*P2(3,9:12) P1(3,2).*P2(3,9:12) P1(3,3).*P2(3,9:12) P1(3,4).*P2(3,9:12)]
A(4,:) = [P1(4,1).*P2(4,13:16) P1(4,2).*P2(4,13:16) P1(4,3).*P2(4,13:16) P1(4,4).*P2(3,13:16)]
A(5,:) = [P1(5,5).*P2(5,1:4) P1(5,6).*P2(5,1:4) P1(5,7).*P2(5,1:4) P1(5,8).*P2(5,1:4)]
A(6,:) = [P1(6,5).*P2(6,5:8) P1(6,6).*P2(6,5:8) P1(6,7).*P2(6,5:8) P1(6,8).*P2(5,5:8)]
A(7,:) = [P1(7,5).*P2(7,9:12) P1(7,6).*P2(7,9:12) P1(7,7).*P2(7,9:12) P1(7,8).*P2(7,9:12)]
A(8,:) = [P1(8,5).*P2(8,13:16) P1(8,6).*P2(8,13:16) P1(8,7).*P2(8,13:16) P1(8,8).*P2(8,13:16)]
A(9,:) = [P1(9,9).*P2(9,1:4) P1(9,10).*P2(9,1:4) P1(9,11).*P2(9,1:4) P1(9,12).*P2(9,1:4)]
A(10,:) = [P1(10,9).*P2(10,5:8) P1(10,10).*P2(10,5:8) P1(10,11).*P2(10,5:8) P1(10,12).*P2(10,5:8)]
A(11,:) = [P1(11,9).*P2(11,9:12) P1(11,10).*P2(11,9:12) P1(11,11).*P2(11,9:12) P1(11,12).*P2(11,9:12)]
A(12,:) = [P1(12,9).*P2(12,13:16) P1(12,10).*P2(12,13:16) P1(12,11).*P2(12,13:16) P1(12,12).*P2(12,13:16)]
A(13,:) = [P1(13,13).*P2(13,1:4) P1(13,14).*P2(13,1:4) P1(13,15).*P2(13,1:4) P1(13,16).*P2(13,1:4)]
A(14,:) = [P1(14,13).*P2(14,5:8) P1(14,14).*P2(14,5:8) P1(14,15).*P2(14,5:8) P1(14,16).*P2(14,5:8)]
A(15,:) = [P1(15,13).*P2(15,9:12) P1(15,14).*P2(15,9:12) P1(15,15).*P2(15,9:12) P1(15,16).*P2(15,9:12)]
A(16,:) = [P1(16,13).*P2(16,13:16) P1(16,14).*P2(16,13:16) P1(16,15).*P2(16,13:16) P1(16,16).*P2(16,13:16)]

1 commentaire

Thanks for asking. If possible. I remain at your disposal for any questions.
Gracias por preguntar. Si es posible. Quedo a su disposición para cualquier consulta.

Connectez-vous pour commenter.

 Réponse acceptée

clear all
n=16;
P1=ones(n);
P2=ones(n);
for p=1:4:13
A(p,:) = [P1(p,p).*P2(p,1:4) P1(p,p+1).*P2(p,1:4) P1(p,p+2).*P2(p,1:4) P1(p,p+3).*P2(p,1:4)];
A(p+1,:) = [P1(p+1,p).*P2(p+1,5:8) P1(p+1,p+1).*P2(p+1,5:8) P1(p+1,p+2).*P2(2,5:8) P1(p+1,p+3).*P2(p+1,5:8)];
A(p+2,:) = [P1(p+2,p).*P2(p+2,9:12) P1(p+2,p+1).*P2(p+2,9:12) P1(p+2,p+2).*P2(3,9:12) P1(p+2,p+3).*P2(p+2,9:12)];
A(p+3,:) = [P1(p+3,p).*P2(p+3,13:16) P1(p+3,p+1).*P2(p+3,13:16) P1(p+3,p+2).*P2(4,13:16) P1(p+3,p+3).*P2(p+3,13:16)];
A
end

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by