フィルターのクリア

sequence/pattern problem

1 回表示 (過去 30 日間)
GMDI
GMDI 2021 年 2 月 8 日
コメント済み: GMDI 2021 年 2 月 9 日
Hi, I have a problem.
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ];
From above A, I want B like below :
B=[1 2 3 4 8 9 10 11 15 16 17 18 ];
Now, if my A is like below:
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24];
Then B will be like below:
B=[1 2 3 4 8 9 10 11 15 16 17 18 22 23 24];
Which means. first four elements of A will be in the B; then the next three elements of A will not be in B; then next 4 elements of A will be in B; and so on so forth..
Last few elements of A will be / will not be in the B depend on if they are in the sequence or not.
I tried to explain the case study above. Please let me know if something is not clear.
Thanks in advance.

採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 8 日
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 ];
B1 = chop43(A(1:20))
B1 = 1×12
1 2 3 4 8 9 10 11 15 16 17 18
B2 = chop43(A)
B2 = 1×15
1 2 3 4 8 9 10 11 15 16 17 18 22 23 24
function B = chop43(A)
full_blocks = floor(length(A)/7);
blocksizes = repmat([4 3], 1, full_blocks);
leftover = length(A) - full_blocks*7;
if leftover > 0 & leftover <= 4
blocksizes(end+1) = leftover;
elseif leftover >= 5
blocksizes(end+1:end+2) = [4, leftover-4];
end
blocks = mat2cell(A, 1, blocksizes);
B = [blocks{1:2:end}];
end
  1 件のコメント
GMDI
GMDI 2021 年 2 月 9 日
Thank you so much for your help. I really appreciate it. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by