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 view (last 30 days)
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.

Accepted Answer

Bob Thompson
Bob Thompson on 19 Sep 2019
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 Comment
Mohammed Alrajeb
Mohammed Alrajeb on 19 Sep 2019
Edited: Mohammed Alrajeb on 19 Sep 2019
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!