Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How to do set subtraction

Asked by Mohammad Golam Kibria

Mohammad Golam Kibria

on 12 Dec 2012
Accepted Answer by Matt Fig

Matt Fig

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.

0 Comments

Mohammad Golam Kibria

Mohammad Golam Kibria

Tags

Products

No products are associated with this question.

2 Answers

Answer by Matt Fig

Matt Fig

on 12 Dec 2012
Edited by Matt Fig

Matt Fig

on 12 Dec 2012
Accepted answer
a = 1:3;
b = 2:5;  
c = setdiff(b,a)

0 Comments

Matt Fig

Matt Fig

Answer by Vishal Rane

Vishal Rane

on 12 Dec 2012

Use

c = b(~ismember(b,a))

although there might be more simpler way to do this.

0 Comments

Vishal Rane

Vishal Rane

Contact us