MATLAB: How to add NaNs to each of a set of vectors of different lengths to make them all the same length please

uneven vectors

I have 13 columns that I'd like to put into a matrix, but they are different lengths. I can add NaN to them to make them the same length; if the max length is say 5000, how do I add NaNs to the others to make them all 5000 please?

Best Answer

Matrix = nan(5000,13);
Matrix(1:length(FirstVariable), 1) = FirstVariable;
Matrix(1:length(SecondVariable), 2) = SecondVariable;
and so on.
If the values were in a cell array then there would be other methods available as well.