MATLAB: Make vectors same length

arrayslengthMATLABMATLAB and Simulink Student Suitevectors

Hello,
I input my data as three different variables, acc, gyr, and mag. I want a small amount of code that makes all three variables the length of the shortest variable.
For example, if acc is 12000×1 and gyr is 12000×1, but mag is 12001×1, how can i automate deleting this row to make the vectors all the same length.
Thank you for your help,
Adam

Best Answer

One way,
collection = {acc,gyr,mag};
minlen = min(cellfun('length',collection));
clipped=cellfun(@(z)z(1:minlen),collection,'uni',0);
[acc,gyr,mag]=deal(clipped{:})
Related Question