フィルターのクリア

Move a columns to the right

8 ビュー (過去 30 日間)
Nour BS
Nour BS 2016 年 1 月 10 日
コメント済み: Star Strider 2016 年 1 月 10 日
Hello everyone, How can I move/shift a set of columns in an array to the right? For example I have
B= [1 3 4 5 2 4; 2 8 6 7 9 8]
and I want to get this result:
S= [1 3 2 4 5 4; 2 8 9 6 7 8].
How can I do this? thank you in advance.

採用された回答

Star Strider
Star Strider 2016 年 1 月 10 日
The only way I can think of to do it is to use the circshift function on columns 3:5:
S = [B(:,1:2) circshift(B(:,3:5),[0 1]) B(:,6)];
  6 件のコメント
Nour BS
Nour BS 2016 年 1 月 10 日
thanks a lot :))))))
Star Strider
Star Strider 2016 年 1 月 10 日
As always, my pleasure!
If you want to rotate your matrices up-down one position instead of left-right one position, the circshift call would be:
S = circshift(B, [-1 0]);
With only two rows, the sign doesn’t have any noticeable effect. With larger matrices, it would.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by