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

remove the repeating values in array

Asked by Elysi Cochin on 28 Nov 2013
Latest activity Commented on by Azzi Abdelmalek on 28 Nov 2013

i have an array with 2 rows 9 columns values

 29	29	29	29	25	25	29	29	27
 13	13	13	13	14	14	13	13	19

i wanted to remove the repeating values and get the output as

 29	25	27	
 13	14	19

what code should i write to remove the repeated values?? please do reply....

0 Comments

Elysi Cochin

Products

No products are associated with this question.

2 Answers

Answer by Andrei Bobrov on 28 Nov 2013
Edited by Andrei Bobrov on 28 Nov 2013
Accepted answer
a = [  29	29	29	29	25	25	29	29	27;
13	13	13	13	14	14	13	13	19];
[ii,ii] = unique(a','rows','first')
out = a(:,sort(ii));

2 Comments

Elysi Cochin on 28 Nov 2013

But sir i'm getting error.....

 ??? Error using ==> unique at 34
 Unrecognized option.
 Error in ==> demoCub at 12
 a1 = unique(a','rows','stable')';
Andrei Bobrov on 28 Nov 2013

corrected

Andrei Bobrov
Answer by Azzi Abdelmalek on 28 Nov 2013
a=[29 29 29 29 25 25 29 29 27;
   13 13 13 13 14 14 13 13 19];
b=a'
[ii,jj]=unique(a','rows')
out=b(sort(jj),:)'

3 Comments

Elysi Cochin on 28 Nov 2013

but if i want it in that order itself what should i do....

 29	25	27	
 13	14	19
Elysi Cochin on 28 Nov 2013

thank u all....

Azzi Abdelmalek on 28 Nov 2013

It's in that order

Azzi Abdelmalek

Contact us