matrix step shift in each row
8 ビュー (過去 30 日間)
古いコメントを表示
HI
i have equestion about matrix shift numbers . for example i have this matrix
A =[ 1 2 3 4 5 ]
i want it to be
A =
1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
3 4 5 1 2
2 3 4 5 1
thank you very much for helping
2 件のコメント
Rik
2021 年 2 月 23 日
Do the numbers in A mean anything (e.g. the number of positions the corresponding row should be shifted), or are you simply asking about a row-wise circshift?
採用された回答
Rik
2021 年 2 月 23 日
This method works without a loop.
A =[ 1 2 3 4 5 ];
[X,Y]=ndgrid(1:numel(A));
X=X(end:-1:1,:);
ind=mod(X+Y,numel(A));
ind(ind==0)=numel(A);
A(ind)
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!