Reputation: 8670
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
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