Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!flph199.ffdc.sbc.com!prodigy.com!flpi107.ffdc.sbc.com!nlpi067.nbdc.sbc.com.POSTED!ffbda4aa!not-for-mail
Reply-To: "Nasser Abbasi" <nma@12000.org>
From: "Nasser Abbasi" <nma@12000.org>
Newsgroups: comp.soft-sys.matlab
References: <giu681$21u$1@fred.mathworks.com>
Subject: Re: How to find maximum values in a matrix
Lines: 47
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350
X-RFC2646: Format=Flowed; Original
Message-ID: <9rx4l.15441$ZP4.9441@nlpi067.nbdc.sbc.com>
NNTP-Posting-Host: 75.40.51.98
X-Complaints-To: abuse@prodigy.net
X-Trace: nlpi067.nbdc.sbc.com 1230152517 ST000 75.40.51.98 (Wed, 24 Dec 2008 16:01:57 EST)
NNTP-Posting-Date: Wed, 24 Dec 2008 16:01:57 EST
Organization: at&t http://my.att.net/
X-UserInfo1: FKPO@MC@OPUUS_DS\@^HJFP@AJYZTB\MV@BL\QMIWIWTEPIB_NVUAH_[BL[\IRKIANGGJBFNJF_DOLSCENSY^U@FRFUEXR@KFXYDBPWBCDQJA@X_DCBHXR[C@\EOKCJLED_SZ@RMWYXYWE_P@\\GOIW^@SYFFSWHFIXMADO@^[ADPRPETLBJ]RDGENSKQQZN
Date: Wed, 24 Dec 2008 13:01:48 -0800
Xref: news.mathworks.com comp.soft-sys.matlab:508691


"Abdul " <spacian1@hotmail.com> wrote in message 
news:giu681$21u$1@fred.mathworks.com...
>I have a  matrix z as below:
>
>       z =
>
>        1218         198
>        1218          22
>        1218        1441
>        1218          28
>        1219          34
>        1219        1789
>
> some elements of matrix z (like 1218 and 1219) in first column are being 
> repeated. I want another matrix which shows these elements (1218 and 1219) 
> only one time with their maximum values (1441 and 1789) in the 2nd column. 
> so the final matrix (suppose p) should be of the form:
>
> p =
>
>        1218        1441
>        1219        1789
> I am a novice in MATLAB Programming. Can anybody please help me?
> Thanks in advance.

one way among many I am sure:

clear all;
A= [1218 198
      1218 22
      1218 1441
      1218 28
      1219 34
      1219 1789];

B=sortrows(A,-2);
[v,I]=unique(B(:,1),'first');
B(I,:)

ans =
        1218        1441
        1219        1789

--Nasser