could anyone help me how to reduce the circshift to half of it.

3 ビュー (過去 30 日間)
Prabha Kumaresan
Prabha Kumaresan 2018 年 8 月 16 日
コメント済み: Prabha Kumaresan 2018 年 8 月 16 日
By using circshift i am getting 12 times what can be done inorder to reduce 12 to 6(which means half of it). Could anyone please help me on this.
  4 件のコメント
Prabha Kumaresan
Prabha Kumaresan 2018 年 8 月 16 日
編集済み: Rik 2018 年 8 月 16 日
yes i can understand circshift does not reduce the length.
this was the code which i am working on
A_master=1:12;
for k=1:numel(A_master)
fprintf('\nPossibilities %02d:\n',k);
A=circshift(A_master,1-k,2);
B=0;
while ~isempty(A)
B=B+1;
if B>numel(A)
ind=1;
B=1;%reset B
else
ind=[1 (numel(A)-B+2):numel(A) ];
end
C=A(ind)
A(ind)=[];
end
end
If i run the code it executes and gives me the result.But I dont want to have all the possibilities. Instead I want to get the possibilities 1,3,5,7,9,11. Could you help me on this.
Stephen23
Stephen23 2018 年 8 月 16 日
編集済み: Stephen23 2018 年 8 月 16 日
@Prabha Kumaresan: this is clearly related to your earlier questions of the last two days. Rather than showing us broken code with no comments or help or explanation, it would actually make things a lots easier if you explained what you are trying to achieve. Forget about your code attempts, they don't help us and are possibly not a very good solution anyway. Show us a simple example, complete with input and output arrays, so that we can understand what you want to achieve.

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

採用された回答

Rik
Rik 2018 年 8 月 16 日
Just change the for-loop header:
A_master=1:12;
for k=1:2:numel(A_master)%[1 3 5 7 9 11] for 12, [1 3 5] for 6, etc
fprintf('\nPossibilities %02d:\n',k);
A=circshift(A_master,1-k,2);
B=0;
while ~isempty(A)
B=B+1;
if B>numel(A)
ind=1;
B=1;%reset B
else
ind=[1 (numel(A)-B+2):numel(A) ];
end
C=A(ind)
A(ind)=[];
end
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by