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) Related SolutionsMATLAB: Question about concatenation in for-loop Instead of cat, use repmat for your case, as you're repeatedly stacking a matrix in a dimension.B = rand(2, 5)C = repmat(B, 1, 1, 5) %stacks B in the 3rd dimension 5 times MATLAB: Creation of matrix A=1:24;B=A*10;C=zeros(24,144);p=0;for k=1:6:144 p=p+1; C(p:end,k)=A(p); C(p:end,k+1)=B(p);endC Related QuestionAnnually averaging of a 4D matrixHave any command for copy variable without loop.How do you stack (using colon) a 3 dimensional matrixCombine 2 char vectors
Best Answer