I was wondering if there is an easy way in MATLAB to do the following operation: I'd like to copy a row or column of a matrix and insert it in the next row/column.
For example: given a 3x3 matrix
1 2 3
4 5 6
7 8 9
I'd like to copy the first row and insert it as a second row:
1 2 3
1 2 3
4 5 6
7 8 9
Can someone advise how I could accomplish this in MATLAB? Thanks!
Move or copy just the contents of a cell You can also edit and select cell data in the formula bar. Select the row or column that you want to move or copy. In the cell, click where you want to paste the characters, or double-click another cell to move or copy the data. or press Ctrl+V.
Any 2 columns (or rows) of a matrix can be exchanged. If the ith and jth rows are exchanged, it is shown by Ri ↔ Rj and if the ith and jth columns are exchanged, it is shown by Ci ↔ Cj.
You can simply repeat the indices of the rows you'd like to repeat
A = A([1 1 2 3],:)
To insert row number source
as row number target
:
A = [A(1:target-1,:); A(source,:); A(target:end,:)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With