Bit missing after circular shift

12 ビュー (過去 30 日間)
Amrita  K
Amrita K 2016 年 4 月 11 日
編集済み: Amrita K 2016 年 4 月 12 日
I have noticed that after performing circular shift, the bit after the shift value is missing.
Shiftvalue = randi(2, n)
n is the max length of array
X = circshift(A, [1, Shiftvalue])
Problem : if Shiftvalue is 25, then the 26th bit is missing. Please help.
  2 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2016 年 4 月 11 日
Can you post an example?
Amrita  K
Amrita K 2016 年 4 月 11 日
編集済み: Image Analyst 2016 年 4 月 11 日
Shiftvalue = 27
A=[1 0 1 1 0 1 1 0 0 1 0 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0]
X=010001100001111111111011100 10110110

サインインしてコメントする。

採用された回答

Roger Stafford
Roger Stafford 2016 年 4 月 11 日
編集済み: Roger Stafford 2016 年 4 月 11 日
Your result can be accounted for if your A row vector is a string vector of 1's amd 0's except that its first element is a blank space character:
A = ' 10110110010001100001111111111011100' (<-- Corrected)
X = circshift(A,[1,27]);
X = 010001100001111111111011100 10110110
Note: The call for a shift of 1 in the rows does nothing to a row vector. Nevertheless you should really have 0 there to get zero shift in case you happen to deal with arrays with more than one row:
X = circshift(A,[0,27]);
  3 件のコメント
Roger Stafford
Roger Stafford 2016 年 4 月 11 日
Yes, I did mean that. Thanks Walter.
Amrita  K
Amrita K 2016 年 4 月 12 日
編集済み: Amrita K 2016 年 4 月 12 日
Thank you Sir, it's working. Appreciate it.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2016 年 4 月 11 日
This works just as expected for me:
ShiftValue = 27
A=[9 0 1 1 0 1 1 0 0 1 0 0 0 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 0 0]
X = circshift(A, [0, ShiftValue])
% Element 1 (which is 9) should now be at element 28.
X(28) % It is 9, just as expected!

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by