Simply use logical indexing directly on a (those b variables are not required):
>> a(~ismember(a,y))
ans =
4 5 6 7 8 9 10 11 12 14 18
>> setdiff(a,y)
ans =
4 5 6 7 8 9 10 11 12 14 18
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!