Search code examples
matlabmatrixrowvarying

Matlab matrix with different Row Sizes


I would like to create a matrix that has different row sizes but I'm not sure where to start.

I have a function that produces time signatures of 5000 photons. Not all those photons will produce meaningful time signatures. That function discards those signatures. I also iterate over this function 5000 times which means my column vector will have varying sizes on each iteration but never more than 5000.

function photon_FWHM = processFates(string,num)

for i = 1:num 
FATES = 'FATES';
str = int2str(i);
filename = strcat(FATES,str);
timestamp = Timestamp(filename);
if timestamp == 0
    continue;
end;
photon_timestamps(:,i) = timestamp;
end;

All in all I will have 5000 columns with some number of rows that vary with column. I'm not sure what a good solution is.


Solution

  • You could also try using cell arrays. Cell arrays may be a little slower, but they can do the job.

    photon_timestamps{i} = vector;

    then each element photon_timestamps{i} can be of different size.

    also your block

    if timestamp == 0
    continue;
    end;
    

    needs a else part right?