How to perform right circular shift

2 ビュー (過去 30 日間)
sadiqa ilyas
sadiqa ilyas 2019 年 11 月 4 日
コメント済み: sadiqa ilyas 2019 年 11 月 5 日
Hi. I have written a code to perform circular shift but it does not give me all X28 and Y28 keys . It returns only one X28 and Y28 with out any circular shift.What I did wrong
key_56=1:56;
x=key_56(1:28);
y=key_56(29:56);
R_key=[1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1];
icount=0;
for i=1:16
icount=icount+R_key(i);
I=icount;
end
%circular shift
X28 = circshift(x', -icount)';
Y28 = circshift(y', -icount)';
  3 件のコメント
Walter Roberson
Walter Roberson 2019 年 11 月 4 日
sum(R_key) is 28, so icount is 28. That is the same as the length of your data, so you are circular shifting each bit of data exactly to the same place it started.
sadiqa ilyas
sadiqa ilyas 2019 年 11 月 4 日
Yes but I want all these outputs. 16 out puts after the circular shift performed according to R_key

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

採用された回答

Walter Roberson
Walter Roberson 2019 年 11 月 4 日
key_56=1:56;
x=key_56(1:28);
y=key_56(29:56);
R_key=[1 1 2 2 2 2 2 2 1 2 2 2 2 2 2 1];
shift_counts = cumsum(R_key);
num_shifts = length(shift_counts);
x_shifted = zeros(num_shifts, length(x));
y_shifted = zeros(num_shifts, length(y));
for i = 1 : num_shifts
x_shifted(i, :) = circshift(x, -shift_counts(i));
y_shifted(i, :) = circshift(y, -shift_counts(i));
end
  1 件のコメント
sadiqa ilyas
sadiqa ilyas 2019 年 11 月 5 日
Thanks

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by