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

Thread Subject:
unique values for 2 columns

Subject: unique values for 2 columns

From: Giuseppe cccc

Date: 19 Oct, 2010 15:29:04

Message: 1 of 6

Hi guys,

that is my problem:
I have to columns, the first one is the position (degree), the second one is the torque (Nm).
e.g.
position torque
6 22
6.1 24
6.1 26
etc.
During the measurement, I got from the system the values in which position is sometimes like 6 6.1 6.1 6.1 6.2 6.3 6.4 6.4 6.5 and the torque which correspond is like 22 24 26 27 28 29 31 33 34
You can notice that for some torque value we have the same position value (e.g. 22 24 26 ----> 6.1 6.1 6.1). That creates some problem for plotting the chart.
Now, I must delete all rows where position values and especially its torque value.

I know the unique function:
positionB = unique(positionA, 'rows')

but I do not know how I can delete at the same time torque values at the same row.

Anyone may help me?
Thanks

Subject: unique values for 2 columns

From: Avi

Date: 19 Oct, 2010 15:49:03

Message: 2 of 6


plot(x,y,'r*') it will plot in points ..

also you can decide several value for x cloumn [ 6 7 8 ] [round all number s,,,]
and make new var 10000*x+y
and on this make unique

Subject: unique values for 2 columns

From: Sean

Date: 19 Oct, 2010 16:18:04

Message: 3 of 6

"Giuseppe cccc" <giuseppino_goldentop@hotmail.com> wrote in message <i9kdg0$lhs$1@fred.mathworks.com>...
> Hi guys,
>
> that is my problem:
> I have to columns, the first one is the position (degree), the second one is the torque (Nm).
> e.g.
> position torque
> 6 22
> 6.1 24
> 6.1 26
> etc.
> During the measurement, I got from the system the values in which position is sometimes like 6 6.1 6.1 6.1 6.2 6.3 6.4 6.4 6.5 and the torque which correspond is like 22 24 26 27 28 29 31 33 34
> You can notice that for some torque value we have the same position value (e.g. 22 24 26 ----> 6.1 6.1 6.1). That creates some problem for plotting the chart.
> Now, I must delete all rows where position values and especially its torque value.
>
> I know the unique function:
> positionB = unique(positionA, 'rows')
>
> but I do not know how I can delete at the same time torque values at the same row.
>
> Anyone may help me?
> Thanks

One way, though there are probably better:

A = [6 6.1 6.1 6.1 6.2 6.3 6.4 6.4 6.5; 22 24 26 27 28 29 31 33 34].'; %Your data
[~,ix,iy] = unique(A(:,1),'rows'); %row indices
idx = ix(accumarray(iy,1,[],@(x)numel(x)==1)); %find doubles and remove them
A(idx,:)

Subject: unique values for 2 columns

From: Oleg Komarov

Date: 19 Oct, 2010 16:30:08

Message: 4 of 6

> One way, though there are probably better:
>
> A = [6 6.1 6.1 6.1 6.2 6.3 6.4 6.4 6.5; 22 24 26 27 28 29 31 33 34].'; %Your data
> [~,ix,iy] = unique(A(:,1),'rows'); %row indices
> idx = ix(accumarray(iy,1,[],@(x)numel(x)==1)); %find doubles and remove them
> A(idx,:)

Another way:
[trash, loc] = unique(A(:,1),'first');
A(loc,:)

You take all the unique values of position and the first corresponding torque value. You can use 'last' or you can use accumarray to take the mean, median etc..

Oleg

Subject: unique values for 2 columns

From: Giuseppe

Date: 21 Oct, 2010 22:06:03

Message: 5 of 6

"Oleg Komarov" <oleg.komarovRemove.this@hotmail.it> wrote in message <i9kh2g$iel$1@fred.mathworks.com>...
> > One way, though there are probably better:
> >
> > A = [6 6.1 6.1 6.1 6.2 6.3 6.4 6.4 6.5; 22 24 26 27 28 29 31 33 34].'; %Your data
> > [~,ix,iy] = unique(A(:,1),'rows'); %row indices
> > idx = ix(accumarray(iy,1,[],@(x)numel(x)==1)); %find doubles and remove them
> > A(idx,:)
>
> Another way:
> [trash, loc] = unique(A(:,1),'first');
> A(loc,:)
>
> You take all the unique values of position and the first corresponding torque value. You can use 'last' or you can use accumarray to take the mean, median etc..
>
> Oleg

Hello Oleg,

thanks to everybody for helped me.
I used the last one proposal done by Oleg.
[trash, loc] = unique(A(:,1),'first');
A(loc,:)
That is allowed me to obtain my values.
Just I noticed that the command creates 3 new variables:
ans
trash
loc
"ans" give me my values correctly but I don't understand what values of "trash" and "loc" variables mean?

thanks

Subject: unique values for 2 columns

From: Oleg Komarov

Date: 21 Oct, 2010 23:44:06

Message: 6 of 6

> Hello Oleg,
>
> thanks to everybody for helped me.
> I used the last one proposal done by Oleg.
> [trash, loc] = unique(A(:,1),'first');
> A(loc,:)
> That is allowed me to obtain my values.
> Just I noticed that the command creates 3 new variables:
> ans
> trash
> loc
> "ans" give me my values correctly but I don't understand what values of "trash" and "loc" variables mean?
>
> thanks

Basically the call to unique returns two outputs: "trash" and "loc".
You can call those two outputs as you wish. I called the first "trash" because you don't need it and the second one just "loc", because it points to the locations you're looking for.

Whenever a command doesn't assing explicitly an output (i.e. no = sign appear) the output is overwritten to "ans"

If still it's not clear I siggest to start from the basics with the getting started guide first 4 chapters.

Oleg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us