jjepsuomi
jjepsuomi

Reputation: 4373

How to remove specific values from a vector in matlab?

If I have for example the following vector of indices:

X = [1 2 3 4 ... 4997 4998 4999 5000]

How can I remove indices in X specified by another vector such as

Y = [9 18 27 36 45 54 63 72 81 ... 981 990 999]

So that after the deletion X would be:

X = [1 ... 8 10 ... 17 19 ... 26 28 ... etc]

Another example would be A = [1 2 3 4 5] and B = [2 5]

so that A-B = [1 3 4]

Thank you for any help

Upvotes: 2

Views: 1520

Answers (1)

niculare
niculare

Reputation: 3687

Try the following formula:

C=setdiff(A, B);

Upvotes: 7

Related Questions