How can I delete numbers in a matrix that is not equal to numbers in another matrix?

1 次查看(过去 30 天)
I know the title may be a little confusing.Say I have A =[1 2 2 3 3 4 4 ] and B = [2 3 4], how can I make A 'realize ' that there is a number in it different from B and delete it? Is there any simple way to do that? I want to avoid loops......Thanks!

回答(1 个)

Lessmann
Lessmann 2015-11-5
Hi,
you can use logical indexing with the 'ismember' function:
A= A(ismember(A,B))

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by