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 .
조회 수: 1 (최근 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.
댓글 수: 0
채택된 답변
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!