How to do set subtraction

I have two array a=[1,2,3] and b=[2,3,4,5]
I need a array c=b\a. Here \ is the set subtract operation. result is as follows:
i.e.c=[4,5]
How to do that in matlab. Thanks in advance.

 采纳的回答

Matt Fig
Matt Fig 2012-12-12
编辑:Matt Fig 2012-12-12
a = 1:3;
b = 2:5;
c = setdiff(b,a)

更多回答(1 个)

Use
c = b(~ismember(b,a))
although there might be more simpler way to do this.

类别

在 帮助中心 和 File 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