Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Find Minimum Values of Matrix without MIN or For loops
Date: Sun, 1 May 2011 21:57:04 +0000 (UTC)
Organization: Ecole Centrale de Nantes
Lines: 17
Message-ID: <ipkkvg$5ti$1@fred.mathworks.com>
References: <ipih48$enm$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1304287024 6066 172.30.248.37 (1 May 2011 21:57:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 1 May 2011 21:57:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2838257
Xref: news.mathworks.com comp.soft-sys.matlab:724711

Ok, here is a one-liner solution

As other answers have pointed, it is difficult to provide an answer to your problem that would have a computational complexity equivalent to the simplest loop that would look for the min over all columns. Yet, this is one of the the point of vectorizing it is sometimes faster to compute too much stuff if an efficient way than just what you need.


>> S = A((repmat(eye(size(A,1)),[1 size(A,1)]) *...
(kron(A,ones(size(A,1),1)) < kron(ones(size(A,1),1),A)))==0)'

basically:
1-use kron to generate all pairwise comparisons between the elements.
2-use a matrix matrix product to reduce all the comparisons and for each element of A, compute how many elements of the column are less than this element.
3-the min over each columns is the element wich have zero in their corresponding entry.
4-use logical indexing to extract the values

Hope this helps.

A.