I want to circular shift rows of ' ww ' this circular shift depend on the numbers of 'r' array in the order , when the r numbers is change the circular shift is change for the ww array rows .

조회 수: 2 (최근 30일)
ww =
1 0 0 1 0 0 1 1 1 0
1 1 1 1 0 1 1 1 0 0
0 0 0 0 1 0 0 1 1 1
0 1 0 0 0 1 0 0 1 0
1 1 1 1 0 0 0 1 0 1
0 0 0 1 1 0 0 0 1 1
0 0 1 0 0 1 0 0 0 1
0 1 1 0 0 1 0 0 0 1
1 1 0 0 1 0 1 1 0 1
0 0 1 1 0 1 0 0 0 0
0 1 0 1 1 0 0 1 0 0
1 1 1 1 1 0 1 0 1 0
1 1 0 0 0 0 0 0 1 0
1 1 0 1 1 0 0 1 1 0
0 0 0 1 1 1 1 1 1 0
1 0 1 0 0 1 1 0 0 1
r =
7 13 3 4 14 14 5 15 3 15 5 10 13 10 12 1
the first row of ww array i must be do circular shift by the first number of r array r=[7] the result must be ww=[1 0 0 1 1 1 0 1 0 0] and second row in ww i must be circular shift by the second number in r arrat r=[13] thus to the end of the ww and r rows.

채택된 답변

Bob Thompson
Bob Thompson 2019년 9월 19일
If I am understanding r correctly, you want to move the respective rows from their current positions to that position plus r(i). I recommend creating an indexing matrix for this, and then using sortrows to perform the reorientation.
I am also assuming that if a relative shift is greater than the number of rows you want to go 'around the horn' and start back up at the top. (i.e. the last row is position + 1, which would make it the first row.)
sr = [1:size(ww,1)];
sr = sr'+r';
sr(sr>size(sr,1)) = sr(sr>size(sr,1))-size(sr,1);
ww = [sr,ww];
ww = sortrows(ww);
ww = ww(:,2:end);
  댓글 수: 1
Mohammed Alrajeb
Mohammed Alrajeb 2019년 9월 19일
편집: Mohammed Alrajeb 2019년 9월 19일
I want in the array (ww) rows are done (circular) depend on the number of numbers in the array (r) for example :
the first row in ww= [1 0 0 1 0 0 1 1 1 0]
I must do circular shift depend on the first number in r array r=[ 7 ]
the result must be ww=[1 0 0 1 1 1 0 1 0 0] in the row is circular shift by 7 times
And so for all rows of the array ww.
the circular shift to right side.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by