MATLAB: Naming new sets of data in for loop and dividing matrixes.

matrix

Hi,
My goal is to divide a 42×525 matrix into 21 42×25 matrixes.
I have 21 sets of data which I have uploaded into matlab in a short for loop
for p = -10:10
filename = strcat('meanfile',num2str(p),'.txt');
line{p+11}=dlmread(filename,'\t',0,0) ;
end
Each data set contain 25 columns and 42 rows, where there are either 18, 32 or 42 rows that have non zero values.
My first code snip made a 1 by 21 cell array where each cell contained a 42×25 matrix. Now to get these into numbers I did a short
for p = 1:21
A = cell2mat(line);
end
This turned by data into a 42×525 matrix. Now what I really want is to divide these into 21 matrixes in a for loop.
I tried something like
for i = 1:21
strcat('line',num2str(i)) = A(1:end,(1:25)*i)
end
however this does not seem to work.
It might be confusing that the lines that are loaded are named from line-10 to line10 and in matlab I try to name them from line 1 to 21, but that is just to avoid non positive integers in the {}.

Best Answer

Why not just load the data into a third dimension from the beginning?
for p = -10:10
filename = strcat('meanfile',num2str(p),'.txt');
line(:,:,p+11)=dlmread(filename,'\t',0,0) ;
end