Reputation: 145
fname = dir('*sir');
[tmp, head] = loadsir(fname(1).name);
dayH = zeros(length(fname),size(tmp,1),size(tmp,2));
% use temporary array to simplify 3d array creation
for i=1:1
tmp = loadsir(fname(i).name);
dayH(i,:,:) = tmp;
end
I have this code above but all I get is:
Error using zeros
Out of memory
Error in dataAnalysis (line 4)
dayH = zeros(length(fname),size(tmp,1),size(tmp,2));
Upvotes: 2
Views: 1608
Reputation: 20319
Arrays in Matlab are stored in consecutive chunks of memory. You are probably running out of memory because your computer doesn't have a continuous block of memory large enough to store the entire matrix.
You need to:
If you don't plan on populating the entire matrix then try reducing its size using a sparse matrix
as suggested by @Dennis Jaheruddin
If you plan on filling the matrix then consider splitting it into cells.
zeroMat = zeros( size(tmp,1), size(tmp,2) );
daysH = repmat( {zeroMat}, [length(fname), 1] );
Each individual cell will still require enough memory for a matrix of size size(tmp,1) x size(tmp2)
. Unless these numbers are huge you should probably be fine.
Upvotes: 2