Path: news.mathworks.com!not-for-mail
From: "James Anderson" <janderson_net@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: how to make the following case vectorized?
Date: Wed, 4 Jun 2008 19:34:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 24
Message-ID: <g26qnb$4nt$1@fred.mathworks.com>
Reply-To: "James Anderson" <janderson_net@yahoo.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1212608043 4861 172.30.248.37 (4 Jun 2008 19:34:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 4 Jun 2008 19:34:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1069706
Xref: news.mathworks.com comp.soft-sys.matlab:472222



Hi, 

I have a matrix (say 10000 rows and 50 columns). I want to
find the rank for each entry within the row it belongs to. I
know how to do this by using a loop, suppose A is the matrix

for k = 1:10000;
  [sortx,ind] = sort(A(k,:));
  rankt(ind) = 1:50;
  Rank(k,:) = rankt;
end

The Rank contains what I need. However, this is going to
take a long time, especially when the number of rows get
even larger. I found the function sort can sort the whole
matrix along one direction, however, is there any vectorized
way to get the Rank very fast without doing any looping? 

Thanks,

James