MATLAB: How to get the dimensions of matrices in cell array

cell arrayimage processingMATLABmatrixnonogramocr resultssort

I have a cell array, which contains coordinates of points in the image (representing the bounding boxes of recognised digits via OCR). I want to sort those digits to rows and columns in order to create a proper multi-dimensional matrix for a puzzle solver. It went pretty well, until I encountered the problem of double-digit numbers, where I want them to treat as one.
ToSortLeft=[leftbboxes,cellfun(@str2num,leftdigits)']% adding the actual nuber into the boundingbox matrix
ToSortLeft=sortrows(ToSortLeft,[2 1]);% sort each digit according to their y coordinate and then according to the x
NumL{1}(1,1:5)=ToSortLev(1,:);
p=2;
k=1;
for i=2:size(ToSortLeft,1)% code to divide rows from each other
if (ToSortLeft(i,2)-ToSortLeft(i-1,2))<SideSize*0.3
NumL{k}(p,1:5)=ToSortLeft(i,:);
p=p+1;
else
k=k+1;
p=1;
NumL{k}(p,1:5)=ToSortLeft(i,:);
p=p+1;
end
end
%%placing the digits to a cell array of matrices
NumLL{1,length(NumL)}=[];
for i=1:length(NumL)
NumL{i}=sortrows(NumL{i},-1);
if length(NumL{i})>1 %if the row contains more than one digit
sz=length(NumL{i}); %here I get an error, becuase I cant find the number of rows with the 'size' neither with the 'length' function in that particular matrix
for j=2:sz
if NumL{1,i}(j-1,1)-NumL{1,i}(j,1)<SideSize/2 %if the numbers are too close
NumL{1,i}(j-1,5)=str2num(strcat(num2str(NumL{1,i}(j,5)),num2str(NumL{1,i}(j-1,5)))); %make one
NumL{1,i}(j,:)=[];%delete the row representing the second digit
sz=sz-1;%decrement the actual number of rows in the matrix
end
end
end
NumLL{i}=fliplr(NumL{i}(:,5)'); %save the vector of digits into the cell array
end
I get an error in the third row, because it contains more digits than one, but less than the x dimension i got from the 'length' function. How can i solve this problem? If there is an easier way to sort these numbers, please tell me.

Best Answer

As a rule, I would never use length because it is often used incorrectly (on a matrix). For a vector I'd use numel. In my opinion, length should be deprecated.
To get the number of rows of the matrix stored in NumL{i} you use size with the dimension set to 1:
numrows = size(NumL{i}, 1);