Selecting more than one range of elements of a vector with a single line code

15 ビュー (過去 30 日間)
Hello everyone,
i'm wondering if it's possible to select more than one range of elements of a vector with a single line code.
For example, given the vector a=[1,2,3,...,100], i'd like to select the two ranges [1,...,10] and [90,...,100]. I know that matlab allows to select only a continous range, e.g.:
a = 1:1:100;
b = a(1+89:100);
Thank you very much in advance.

採用された回答

Bruno Luong
Bruno Luong 2018 年 12 月 8 日
a([1:10, 90:100])
  1 件のコメント
Gennaro Arguzzi
Gennaro Arguzzi 2018 年 12 月 8 日
Hello @Bruno Luong, your solution is very useful and elegant. Thank you a lot.

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

その他の回答 (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