Quantcast
Channel: MATLAB Central Newsreader Recent Posts
Viewing all articles
Browse latest Browse all 19628

Re: Removing vector elements that exist in another vector

$
0
0
On 11/19/2012 11:33 PM, Nasser M. Abbasi wrote:

>>
>
>> A(ismember(A,H1))=[]
>>
>
> fyi;
>
> another way is
>
> A = setdiff(A,H1);

Just watch out, that setdiff() returns the result SORTED,
while the first solution leaves things as is.
  
This might be ok for your A or not. It depends on your
use. But you can still use setdiff() if you want, and
get the order back the way it was in A, since setdiff
have another way to be called where it return the indices
used (see help). But this means another extra step to
'unsort' things to the way it was.

I did not see an option to tell setdiff() NOT to sort the result,
but I might have missed it.

--Nasser

Viewing all articles
Browse latest Browse all 19628

Trending Articles