MATLAB: 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 .

matrixmatrix manipulation

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.

Best Answer

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);