필터 지우기
필터 지우기

Move particular column to specified index

조회 수: 32 (최근 30일)
Rishi Balasubramanian
Rishi Balasubramanian 2020년 12월 19일
댓글: Rishi Balasubramanian 2020년 12월 20일
Hey assume I have a matrix 50x100
In an automated function I will be needing to select particular column, and move it to specified position without messing up the rest of the order. I am looking for a remove and insert type, NOT SWAP.
For ex, I want to move column 30 to 60th position. I am expecting the result like Columns = [ 1:29 31:60 30 61:100]. I tried using this
Halt = [Halt(:, 1:(pcol-1)) Halt(:, (pcol+1):(p)) Halt(:,pcol) Halt(:, (p+1) : end)];
I want to know if there is anyother easier efficient way to do this.
Any help would be appreciated. Thank You.

채택된 답변

Cris LaPierre
Cris LaPierre 2020년 12월 19일
편집: Cris LaPierre 2020년 12월 19일
There is not a special function for this. The best ways for doing this in MATLAB is to specify the new column order.
A = [1:3;11:13]
A = 2×3
1 2 3 11 12 13
% Move column 1 to 2nd position by specifying new column order
B = A(:,[2 1 3])
B = 2×3
2 1 3 12 11 13
  댓글 수: 1
Rishi Balasubramanian
Rishi Balasubramanian 2020년 12월 20일
Unfortunately you are right. I just stuck with what I already had in the end. Thanks though.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by