|
Hi,
I have been working on trying to improve my CPU time. I generated a set of data and have arranged them in such a way where I have three large matrices that are NxNx300 sample points. I implemented this by using cell arrays. When I run my code, I notice that it takes 6 hours at least to execute one section of my code and that is due to nested for loops that I have. I would like to find a way to fetch data one at a time for
3 huge cell array matrices (T1, T2 and T3) that are NxNx300 and perform the following multiplication T_tot=T1*T2*T3 so that my result is T_tot is NxNx300. Here's a sample of my code that implements this approach using nested for loops.
sampleSize=300;
cell_array=676;
trans_matrix_size=2*cell_size;
mat_A=zeros(trans_matrix_size,trans_matrix_size);
mat_B=zeros(trans_matrix_size,trans_matrix_size);
mat_C=zeros(trans_matrix_size,trans_matrix_size);
mat_D=zeros(trans_matrix_size,trans_matrix_size);
nx1=0;
nx2=0;
ny1=ny2=ny3=ny4=0;
for x=1:1:sampleSize
for mrow=1:1:trans_matrix_size
if(mrow <= cell_size)
nx1=nx1+1;
else
nx2=nx2+1;
end
for mcol=1:1:trans_matrix_size
if(mcol <= cell_size && mrow <= cell_size)
ny1=ny1+1;
ny3=0;
mat_A(mrow,mcol)=TA{nx1,ny1}(x); % TA, cell_size x cell_size x 300
mat_B(mrow,mcol)=TA{nx1,ny1}(x); % identity matrix
mat_C(mrow,mcol)=TA{nx1,ny1}(x);
elseif(mcol <= cell_size && mrow > cell_size)
ny2=ny2+1;
ny4=0;
mat_A(mrow,mcol)=TC{nx2,ny2}(x); % TC, cell_size x cell_size x 300
mat_B(mrow,mcol)=Y{nx2,ny2}(x); % zero matrix
mat_C(mrow,mcol)=TC{nx2,ny2}(x);
elseif(mcol > cell_size && mrow <= cell_size)
ny3=ny3+1;
ny1=0;
mat_A(mrow,mcol)=TB{nx1,ny3}(x);
mat_B(mrow,mcol)=TC{nx1,ny3}(x);
mat_C(mrow,mcol)=TB{nx1,ny3}(x);
elseif(mcol > cell_size && mrow > cell_size)
ny4=ny4+1;
ny2=0;
mat_A(mrow,mcol)=TA{nx2,ny4}(x);
mat_B(mrow,mcol)=TA{nx2,ny4}(x);
mat_C(mrow,mcol)=TA{nx2,ny4}(x);
end
end
end
mat_D(mrow,mcol)=mat_A*mat_B*mat_C;
end
Thanks for your help...
|