How to shift diffrent rows with diffrent shift positions in matlab?
1 回表示 (過去 30 日間)
古いコメントを表示
I want to right shift each row of P with different shift position.
P =
1111100100000000
0000100000000000
0000001110000000
1111110010000000
Here, class(P) = char . I want:
P =
1111111111111001
0000000000001000
0000000000000111
0000000111111001
Follwong code i have used for determining the number of shift positions:
[rows cols] = size(P); %4 , 16
x = zeros(rows,cols);
k =1;
for i = 1:rows
c=0;
for m = cols:-1:9 %This loop finds the number of 0s with in 16 to 9 %column for each rows and stops when it gets 1 with in these columns.
if (P(i,m) == '0')
c = c+1;
else (P(i,m) == '1'), break,
end
end
c
end
Here c is the number of right shift position for each rows but how this right shift operation can be performed?
And while shifting, column 1 value of each row (P(:,1)) will be filled instead of zero filling at left side.
How this shift operation can ne performed?
0 件のコメント
回答 (2 件)
Sean de Wolski
2011 年 12 月 12 日
Without looking too much into your code, it looks like circshift might be your friend.
doc circshift
0 件のコメント
Andrei Bobrov
2011 年 12 月 12 日
A = ['1111100100000000'
'0000100000000000'
'0000001110000000'
'1111110010000000']
Aout1 = [circshift(A(1:2,:),[ 0 8]);circshift(A(end-[1 0],:),[ 0 7])]
Aout1(1,1:strfind(Aout1(1,:),'011'))='1'
or
A = [A(1:2,[9:end,1:8]);A(3:4,[10:end,1:9])];
A(1,1:8) = '1'
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!