MATLAB: Dimensions of matrices being concatenated are not consistent.

image processingImage Processing Toolbox

I have 1*512 cell and i want it to convert in matrix so i am trying to use cell2mat but i am getting this error :
Error using cat
Dimensions of matrices being concatenated are not consistent.
Error in cell2mat (line 75)
m{n} = cat(2,c{n,:});
i have obtained this cell after using
cellfun(@(x) find(x,1,'first'), cimg,'un',0);
Uploading the mat file for 1*512 as well.

Best Answer

You have empty ( see comments below! ) arrays in your cell array (where FIND found nothing), so the dimensions do not match for a CAT (the content of some cells is 1x1 and the content of others is 1x0).
If you can get rid of these empty arrays (and hence reduce the number of elements in the output), you can do something like:
isEm = cellfun( @isempty, ridx ) ;
data = cell2mat( ridx(~isEm) ) ;
where data contains the 502 "non-empty values". If you need to keep the size of the original data, you can replace empty arrays with e.g. NaNs:
ridx(isEm) = {NaN} ;
data = cell2mat( ridx ) ;
and here data has 512 elements, 10 of which are NaN.