MATLAB: Finding the matrix with the most elements

maximum valuevectors

Hello all,
I'm kinda new to matlab so I'm still trying find my way through the way things work. That said I have a question that I need some help on:
I have 3 matrix arrays of varying sizes, called say V1, V2, and V3. How would I go about programming the code so that matlab finds the matrix with the most elements.
I want to save the number of elements in the largest matrix as it's own variable, "LarMat", and I know how to do that already, it's just that finding the largest of the three is giving me some trouble.

Best Answer

This is one way:
V1 = rand(2,2);
V2 = rand(3,3);
V3 = rand(4,4);
[els,idx] = max([numel(V1) numel(V2) numel(V3)]);
The ‘els’ variable will tell you the maximum number of elements, and the ‘idx’ variable will tell you which one. (It is ‘V3’ — the third matrix whose elements are determined — here.)