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!