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
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?
mohammed hussein
mohammed hussein 2021년 2월 23일
yes , i have circle geometry , i want to shift the number in circle like the simple example that i asking about

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

 채택된 답변

Rik
Rik 2021년 2월 23일

0 개 추천

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)
ans = 5×5
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

추가 답변 (1개)

Stephen23
Stephen23 2021년 2월 23일

0 개 추천

A = [1,2,3,4,5];
B = toeplitz(A([1,end:-1:2]),A)
B = 5×5
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

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2021년 2월 23일

댓글:

2021년 2월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by