Extracting every nth and (n+1)th element

43 ビュー (過去 30 日間)
Inna Pelloso
Inna Pelloso 2020 年 12 月 6 日
コメント済み: Inna Pelloso 2020 年 12 月 6 日
Hi,
I have A = (1:101). How can I extract every nth and (n+1)th element?
For example, if n = 10, I want reate B = [10, 11, 20, 21, ...100, 101].
I know how to extract every nth element using: A(1:n:end).
Any help would be appreciated! Thank you.
Inna

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 12 月 6 日
I'm not aware of any slick way to do this. I'd combine two arrays, one from 10:10:101, and one from 11:10:101.
n=10;
A = (1:101);
ind = sort([n:n:101 n+1:n:101]);
A(ind)
ans = 1×20
10 11 20 21 30 31 40 41 50 51 60 61 70 71 80 81 90 91 100 101

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by