简体   繁体   中英

How to get back the elements of array which are not defined in an index array?

For example, I have following array in MATLAB:

a = 11:20 ;

and I want to to extract the elements from a which are not defined among the below index elements:

b = [2,3,5];

If I execute the following line of get:

a(b)

ans =

    12    13    15

I am looking for a method which is just opposite of above and without introducing loop to get the elements from a and index of those elements is not present in index array b .

setdiff是您要寻找的功能。

a(setdiff(1:end,b))

An alternative approach:

>> a = 11:20;
>> b = [2,3,5];
>> c = a;
>> c(b) = []
c =
   11   14   16   17   18   19   20

c(b)=[] deletes from c the elements indexed by b .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM