Select a set of variables from an array NOT equal to a set of indices

11 ビュー (過去 30 日間)
ZigzS
ZigzS 2018 年 5 月 1 日
回答済み: Walter Roberson 2018 年 5 月 1 日
I need to select all of values in an array except for specified indices.
A=[1 2 3 4 5 6 7 8 9];
set=[1 3 5];
B = A(~set); %this is the issue
I want to get a new vector which contains all of the values of A except for indices 1 3 and 5. So the output would be
B=[2 4 6 7 8 9];
Appreciate the help.

回答 (2 件)

Geoff Hayes
Geoff Hayes 2018 年 5 月 1 日
Reid - how about trying
B = A;
B(set) = [];
and those elements at indices 1,3,5 should now be removed from B.

Walter Roberson
Walter Roberson 2018 年 5 月 1 日
B = A(setdiff(1:length(A), set))

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by