MATLAB Answers


how to delete an element from a particular position from a vector of repetitive elements

Asked by naman
on 23 Mar 2013

I want to delete the element from a particular position in the vector as I have repetitive elements in that vector.

For example, I have

A =[1 2 3 2 5];

and I want to delete 2 from 4th position. Help me out



No products are associated with this question.

2 Answers

Answer by Cedric Wannaz
on 23 Mar 2013
 Accepted answer

You might just want to use UNIQUE..

 >> b = unique(A) ;


Andrei Bobrov
on 23 Mar 2013
b = unique(A,'stable');
Cedric Wannaz
on 23 Mar 2013

Yes, I assumed 'sorted' as the outcome of removing the 4th element is a sorted vector, but I should have made this assumption explicit and mentioned 'stable.

Answer by naman
on 24 Mar 2013

Thanks for the answer, its working for this particular vector. But here the condition is bit different. I mentioned from a particular position because I can have the vector of type

A=[ 1 2 3 2 5 2]

now again, i want to remove only 4th element. So pl consider according to generalize vector. Thanks

  1 Comment

Cedric Wannaz
on 24 Mar 2013
 A(4) = []

if you want to remove only element #4.

Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!