MATLAB: Concatenation in a loop concatenationloop Can we concatenate two matrices in a loop? (size of one matrix will increase after every iteration) for me its showing this error "Error using cat Dimensions of matrices being concatenated are not consistent." Best Answer For row wise concatenation:Here, matrix 'c' is being concatenated to matrix 'a' row wise, number of columns being constant in this case.a = [];c = [1 2;3 4];for i = 1:5 c = [1*i 2*i;3*i 4*i]; a = [a;c]; % For row wise concatenationendFor column wise concatenation:Here matrix 'c' is being concatenated to matrix 'a' column wise, number of rows being constant in this case.a = [];c = [1 2;3 4];for i = 1:5 c = [1*i 2*i;3*i 4*i]; a = [a c]; % For column wise concatenationendHope this helps Related SolutionsMATLAB: Dimension mismatch error in matrix. C(:, 2:2:2*size(B,2))=B; C(:, 1:2:end)=A; MATLAB: Transfer a matrix in a quick way If you want to preserve each 4x3 block, you could try something like this:B = reshape(A(:, [1:3:end, 2:3:end, 3:3:end]), [], 3 ); Related QuestionHow to delete entire row when both cell in column B and C is emptyHow to delete entire row if any cell of the particular row is emptyFixing dimension mismatch in quadprogHow can you conform one value of one matrix to all values of anotherGather many tables in one table
Best Answer