MATLAB: Insert first element into existing column vector…

insert elementvector

Hello,
I am trying to just insert a 0 into my 48×1 double vector z, like this:
array = [0.0,z]
I keep getting:
Error using horzcat Dimensions of matrices being concatenated are not consistent.
What am I missing?

Best Answer

You should join them by using vertcat. Note that your z is row matrix.
z = rand(48,1) ;
array = [0.0 ;z] % method 1
array = vertcat(0,z) % or use vertcat