Yuseferi
Yuseferi

Reputation: 8670

Exclude some data from a vector

Let's suppose I have a vector that contain numbers between 1..100, and then I generate some number randomly (let's suppose five item and random Items are [3 5 45 66 77]. Then I want to exclude this item from my data.

data = [1..100]
blocklistitems=[3 5 45 66 77]
cleandata = data exclude blocklist

How can I exclude some data from a vector in Matlab?

Upvotes: 1

Views: 214

Answers (1)

Adriaan
Adriaan

Reputation: 18177

data = [1..100]
blocklistitems=[3 5 45 66 77]
data(blocklistitems)=[]; %// completely removes, reduces length of array
data(blocklistitems)=nan; %// sets to nan

Utilising indexing!

Judging your comment I think your data is not as simple as you present in your answer, since in that case the indexing way is the fastest by far. Taking @Divakar's comment using setdiff the same can be accomplished for non-consecutive integer arrays:

C = setdiff(data,blocklistitems);

Upvotes: 6

Related Questions