Move particular column to specified index
18 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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]
% Move column 1 to 2nd position by specifying new column order
B = A(:,[2 1 3])
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!