MATLAB Answers

Rita
0

How I can extract data from a vector based on index

Asked by Rita
on 3 Jun 2016
Latest activity Commented on by 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!

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by Roger Stafford on 3 Jun 2016
Edited by Roger Stafford on 3 Jun 2016
 Accepted Answer

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));

  1 Comment

Thanks Roger

Sign in to comment.