help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using the unique command without sorting the values and getting the


From: Francesco Potortì
Subject: Re: Using the unique command without sorting the values and getting the rows
Date: Wed, 15 Jun 2016 18:52:57 +0200

>I'm trying to get all the rows based on the unique values found in the
>second column.  see example below

>C=[
>1, 103.4025175681402,    103.4104224840438,    0.007904915903608867;
>2, 102.1231938014567,    102.1146017352405,    0.00859206621620956;
>3, 97.5338137548381,    97.53996181901071,    0.006148064172606382;
>4, 97.54468038366592, 97.53996181901071,    0.004718564655206592;
>5, 93.76199482417094,    93.77030145885571,    0.008306634684771552;
>6, 93.77539643924416,    93.77030145885571,    0.005094980388449244;
>7, 106.976493571217,    106.9837463671074,    0.007252795890309471]
>
>The final array I'm trying to get
>D=
>[
>1, 103.4025175681402,    103.4104224840438,    0.007904915903608867;
>2, 102.1231938014567,    102.1146017352405,    0.00859206621620956;
>3, 97.5338137548381,    97.53996181901071,    0.006148064172606382;
>5, 93.76199482417094,    93.77030145885571,    0.008306634684771552;
>7, 106.976493571217,    106.9837463671074,    0.007252795890309471];

I suppose you meant the third column.  Here you are:

> format long g
 
> C=[
1, 103.4025175681402,    103.4104224840438,    0.007904915903608867
2, 102.1231938014567,    102.1146017352405,    0.00859206621620956
3, 97.5338137548381,    97.53996181901071,    0.006148064172606382
4, 97.54468038366592, 97.53996181901071,    0.004718564655206592
5, 93.76199482417094,    93.77030145885571,    0.008306634684771552
6, 93.77539643924416,    93.77030145885571,    0.005094980388449244
7, 106.976493571217,    106.9837463671074,    0.007252795890309471];

> [~, idx] = unique(C(:,3), 'first');

> C(sort(idx), :)
ans =

  1       103.40251756814      103.410422484044   0.00790491590360887
  2      102.123193801457       102.11460173524   0.00859206621620956
  3      97.5338137548381      97.5399618190107   0.00614806417260638
  5      93.7619948241709      93.7703014588557   0.00830663468477155
  7      106.976493571217      106.983746367107   0.00725279589030947

-- 
Francesco Potortì (ricercatore)        Voice:  +39.050.621.3058
ISTI - Area della ricerca CNR          Mobile: +39.348.8283.107
via G. Moruzzi 1, I-56124 Pisa         Skype:  wnlabisti
(entrance 20, 1st floor, room C71)     Web:    http://fly.isti.cnr.it




reply via email to

[Prev in Thread] Current Thread [Next in Thread]