how to move a row

6 Ansichten (letzte 30 Tage)
Miri
Miri am 9 Jun. 2022
Kommentiert: Jeffrey Clark am 9 Jun. 2022
I have a 802x1. I would like to move/insert row 801 right after 400. so that 801 is the new 401.
  2 Kommentare
Jeffrey Clark
Jeffrey Clark am 9 Jun. 2022
If m is a matrix m = [m(1:400,:);m(801,:);m(401:800);m(802:end,:)];
If m is a row vector remove the ,: in each above.
If m is a column vector or otherwise I don't understand the question.
Jeffrey Clark
Jeffrey Clark am 9 Jun. 2022
@Miri you could do this implace if you are concerned with the memory associated with creating another array/matrix:
m801 = m(801,:);
m(402:801,:) = m(401:800,:);
m(401,:) = m801;

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

James Tursa
James Tursa am 9 Jun. 2022
result = M([1:400,801,401:800,802])

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by