MATLAB: How to cut down the size of an array of data

arraydataMATLABsizing

I have a few arrays, with one column each, of different sizes (200127, 200126, 200120, etc.) In order to preform the calculations I want to do, I need them to all be the same length. Is there a way to cut them all down to the smallest array I have?

Best Answer

It'd be easier if there weren't different variables, but since they're inconsistent in length that makes it a little more of a pain unless you were to initially use a cell array where each cell column contained one of these arrays.
But, the syntax you're looking for to do the size reduction is
[mn,imn]=min(length(A),length(B),...,length(Z)); % minimum length of all your arrays and which one
A(N+1:end)=[];
B(N+1:end)=[];
C(N+1:end)=[];
... % you get the picture, excepting, of course for whichever variable it is that corresponds to variable imn
Alternatively, you can save instead of cull...
A=A(1:N);
B=B(1:N);
C=C(1:N);
...
this way you don't need to worry about which doesn't have >N elements.
Of course, going on into the problem, you'll undoubtedly want to end up with
Data=[A(1:N) B(1:N) C(1:N) ... Z(1:N)];
so you can now programmatically address all by simply using subscripting expressions instead of having superfluous variables to deal with.
How were these arrays created in the first place? Quite possibly you could have solved all the issues while reading them or some other way before got into this fix.