Bootstrap

matlab 多重 for,如何用矩阵运算代替多重for循环,求助!!!

function test

clear;clc;

N1=3;N2=4;N3=5; N4=2;

M1=6;M2=7;M3=9; M4=8;

Q_n1_n2_n3_n4_2=cat(5,randi(50,N1,N2,N3,N4),randi(50,N1,N2,N3,N4)); % 把Q1,Q3扩展到第5维

Q_m1_m2_m3_m4_2=cat(5,randi(50,M1,M2,M3,M4),randi(50,M1,M2,M3,M4)); % 把Q2,Q4扩展到第5维

n1_m1=randi(50,N1,M1);

n2_m2=randi(50,N2,M2);

n3_m3=randi(50,N3,M3);

% --------------------  使用"for循环"的方法(灵活,可读性好) -------------------------

tic

F_n4_m4=zeros(N4,M4);

for n1=1:N1 ,for m1=1:M1

for n2=1:N2, for m2=1:M2,

for n3=1:N3, for m3=1:M3

for n4=1:N4, for m4=1:M4

F_n4_m4(n4,m4)=F_n4_m4(n4,m4)+ ...

n1_m1(n1,m1)*n2_m2(n2,m2)*n3_m3(n3,m3)* ...

(Q_n1_n2_n3_n4_2(n1,n2,n3,n4,1)*Q_m1_m2_m3_m4_2(m1,m2,m3,m4,1)+ ...

Q_n1_n2_n3_n4_2(n1,n2,n3,n4,2)*Q_m1_

;