# loop to create the new matrix which contains the kron product

1 visualizzazione (ultimi 30 giorni)
Kantosa il 6 Dic 2013
Commentato: sixwwwwww il 9 Dic 2013
Hi,
So I have created a 3*3 matrix for A and B as shown below
A=round(rand(3,3)*10-5)
B=round(rand(3,3)*20-10)
now the question has ask me to use the nested loop to create the new matrix which contains the Kronecker product K=A*B
for i=1:3
for ii=1:3
K=A(i,ii)*B
end
end
I've attempted to do this by creating this nested loop, it generates 9 answers for K and I don't really know how to combine these answers into one matrix of 9*9. I am not sure if this method is right. It would be great if anyone can help me with this.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Roger Stafford il 6 Dic 2013
K = zeros(3*3,3*3);
for i=1:3
for ii=1:3
K(3*i-2:3*i,3*ii-2:3*ii) = A(i,ii)*B;
end
end
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Kantosa il 9 Dic 2013
Thank you :)

Accedi per commentare.

### Più risposte (1)

sixwwwwww il 6 Dic 2013
Modificato: sixwwwwww il 8 Dic 2013
you can do it as follows:
A = round(rand(3,3)*10-5);
B = round(rand(3,3)*20-10);
for i = 1:size(A, 1)
for j = 1:size(A, 2)
AB{i, j} = A(i, j) * B;
end
end
AB = cell2mat(AB);
disp(AB)
Good luck!
##### 2 CommentiMostra NessunoNascondi Nessuno
Kantosa il 9 Dic 2013
Thank you :)
sixwwwwww il 9 Dic 2013
you are welcome

Accedi per commentare.

### Categorie

Scopri di più su Logical in Help Center e File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by