exclude some elements in array

80 ビュー (過去 30 日間)
Rica
Rica 2021 年 5 月 31 日
回答済み: Rica 2021 年 5 月 31 日
Hi all,
how could i exclude the bold number from this arry. The array is large but it shows the structure that after each 5 element, 3 element should be excluded.
Thank you!
2.70850000000000
2.63220000000000
2.25820000000000
2.45430000000000
2.99680000000000
-54.2462960000000
NaN
NaN
2.25420000000000
2.92210000000000
1.70920000000000
2.06580000000000
2.17260000000000
3.1726950000000
NaN
NaN

採用された回答

Torsten
Torsten 2021 年 5 月 31 日
last = numel(a);
idx = [6:8:last,7:8:last,8:8:last];
a(idx) = [];

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2021 年 5 月 31 日
a8 = reshape(a, 8, []);
a = reshape(a8(1:5,:), [], 1);
Note: Torsten's solution is more robust for the situation where the array is not an exact multiple of 8 entries.
If you have the communications toolbox, you could also use
a8 = buffer(a, 8);
a = reshape(a8(1:5,:), [], 1);
This would pad short buffers. If the missing data was in the last 3 expected entries, you would never notice the padding, but if you had a partial group of 1 to 4 elements long, then buffer() would fill out to make a full group.

Rica
Rica 2021 年 5 月 31 日
Thank you everyone!

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by