Consider I have a vector a
of size 5x1
and I pad zeros at the beginning of this vector. The number of zeros are generated using the randn
function. Due to the randn
, the vector is padded by a random number of zeros in a for
loop. I would like to store these varying size vectors in a single matrix and I am unable to figure a way how to do this (other than fixing the size of the matrix before hand. Here is a MWE for the same:
a = rand(5,1)
for ii = 1 : 6
delay = round(abs(randn(1,1)));
shifted_a = [zeros(delay,1);a];
temp_mat(:,ii) = shifted_a
end
In the second iteration, matlab will definitely throw an error due to the assignment mismatch at temp_mat(:,ii) = shifted_a
. Is there a way I can have all these vectors in a matrix without having to fix the size of the matrix in advance.