MATLAB Answers

How I can extract data from a vector based on index

14 views (last 30 days)
Rita on 3 Jun 2016
Commented: Rita on 6 Jun 2016
I have an index and a vector I would like to have data from the vector which is not in the index!For example
A=[5 3 7 8 89 6]
index=[2 3 4 5]
Now I want to have B as my answer B=[5 6] Thanks!


Sign in to comment.

Accepted Answer

Roger Stafford
Roger Stafford on 3 Jun 2016
Edited: Roger Stafford on 3 Jun 2016
B = A(setdiff((1:length(A)).,index(:)));
or if you're sure A and index are row vectors just
B = A(setdiff(1:length(A),index));

More Answers (0)

Sign in to answer this question.