MATLAB: How to add a row and column to a matrix add column and row to matrixMATLAB eg. A = [1 2 3 4 5 6 7 8 9]; and transform it to; A = [1 2 1 3 4 5 1 6 1 1 1 1 7 8 1 9]; Best Answer One easy option is to do this for rows and columns separatelyA = [1 2 3 ; 4 5 6 ; 7 8 9]x = 3 ; % add a row/column of ones before this row/columnA(end+1, :) = 1 % add row add the endA([x end], :) = A([end x], :) % swap the x-th and last row% do the same for columnsA(:, end+1) = 1A(:, [x end]) = A(:, [end x]) Related SolutionsMATLAB: How can i add column in matrix Depends what you want in that column but you could for example add a column of zeros as follows:A = [A zeros(size(A,1),1)] MATLAB: How to delete rows from a matrix when the values of certain columns are equal Try>> M = [1 1 7 8; 2 3 6 9; 5 8 10 8; 4 4 3 1]M = 1 1 7 8 2 3 6 9 5 8 10 8 4 4 3 1>> M( M(:,1)==M(:,2),:)=[];>> MM = 2 3 6 9 5 8 10 8and look up logical indexing in the Help. Related QuestionHow tonsert Column and Row in all dimensions of a matrixHow sort rows of matrix as per given indexFor same Matrix subtraction between rows
Best Answer