MATLAB: How to shorten this code to remove one piece of information from each submatrix

MATLABmatrixsubmatrices

I currently have a Matrix (Mcell) made up of 27390 submatrices which are either 2 by 2. or 1 by 1.
For example:
Mcell{1,1} = 8 -0.5
24 -0.6
I need to extract the value 8 (In the 1,1 position) from each of the sub-matrices and have it in a list it doesn't matter if it's a column or a row.
So far I can do this using this code:
A=[Mcell{1,1}(1,1) Mcell{2,1}(1,1) Mcell{3,1}(1,1) Mcell{4,1}(1,1) Mcell{5,1}(1,1)];
But that only works for the first 5, and I need to replicate it for all of them.
I have tried doing the following:
for i= 1:27390;
A=[Mcell{i,1}(1,1)];
end
But it just gave me the 1,1 value for Mcell{27390,1}. Rather than a list of values.
I also need to do this for the {2,1} position of each submatrix but I'm hopeful I can use the same code for both.
It would also need to preserve the length (27390), so where there wasn't a submatrix value for the (2,1) position a '0' needs to go in it's place.
Many thanks

Best Answer

Since all your 2D matrices are the same size you might as well all store them as pages of a 3D matrix. This would make your problem easy to solve with simple indexing:
Mmatrix = cat(3, Mcell{:}); %concatenate all matrices along the 3rd dimension
%get element (1, 1) of all matrix:
A = squeeze(Mmatrix(1, 1, :))
The reason your for loop does not work is because you don't do any concatenation in the loop. You just keep on overwriting A all the time. This would work
A = [];
for idx = 1:numel(Mcell) %don't hardcode matrix size when you can simply ask matlab what it is
A = [A, Mcell{idx}(1, 1)];
end
but would be extremely slow due to the constant resizing. This would be slightly faster:
A = zeros(1, numel(Mcell));
for idx = 1 : numel(Mcell)
A(idx) = Mcell{idx}(1, 1);
end
But my first solution is the fastest and most flexible.