Mathworks specifically documents that you cannot do a partial load of a cell array.
You would have to break up your cell array into variables when you stored it in the matfile. For example,
chunksize = 10;
varbase = 'MyVar';
chunkname = cat(varbase, '_chunk_');
m = matfile('myFile.mat','Writable',true);
varlen = size(MyVar, 1);
chunklist = [1 : chunksize : varlen, varlen+1];
numchunks = length(chunklist) - 1;
chunknames = cell(numchunks,1);
for chunknum = 1 : numchunks
thisvarstr = sprintf('%s%d', chunkname, chunknum);
m.(thisvarstr) = MyVar(chunklist(chunknum):chunklist(chunknum+1)-1,:);
chunknames{chunknum} = thisvarstr;
end
chunkinfo = struct('chunklist', chunklist, 'chunksize', chunksize, 'size', size(MyVar), 'chunknames', chunknames, 'chunkname', chunkname);
chunkinfostr = cat(chunkname, 'info');
m.(chunkinfostr) = chunkinfo;
This produces file variables MyVar_chunk_info with some descriptive information, and MyVar_chunk_1 MyVar_chunk_2 and so on to hold the information.
Given any particular column index, the chunk number can be computed based upon chunksize. Or you could use the chunk list, which is structured as a list of boundaries such as [1 11 21 22] with the N'th chunk starting at the cell index given in the N'th entry and ending before the cell index given in the next entry -- so the above list would describe chunks with indices {1:10, 11:20, 21}.
[counts, chunknumber] = histc(rowindexlist, chunklist);
Adapt for whatever flexibility you need.
Best Answer