MATLAB: How to fill matrix without using for loop

without using for loop

a=zeros(24,4); b=ones(24,1);
Why does not this work?
a(:,1:end)=b(:)
Subscripted assignment dimension mismatch.
Does anyone know where I am going wrong? bold

Best Answer

Are you trying to replicate b through A? In which case use the repmat function:
A = repmat(b,24,1)
Edit: Just realised that b is a column, so it should be A = repmat(b,1,4)