From: "Bruno Luong" <b.luong@fogale.findmycountry>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Find function
Date: Sat, 22 Nov 2008 09:35:02 +0000 (UTC)
Organization: FOGALE nanotech
Lines: 28
Message-ID: <gg8jo6$bi0$>
References: <gg8c2k$s8d$>
Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry>
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: 1227346502 11840 (22 Nov 2008 09:35:02 GMT)
NNTP-Posting-Date: Sat, 22 Nov 2008 09:35:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 390839
Xref: comp.soft-sys.matlab:502475

"Gordon " <> wrote in message <gg8c2k$s8d$>...
> I&#8217;m attempting to run a find command on two vectors A and B, I want to find the number of occurrences in vector a  that are <= every occurrence in vector b.  I can do this easily with a for loop, but it takes forever to run on large vectors.  Here is my code&#8230;
> y=zeros(length(a),1);
> for i = 1:length(a)
>    a1 = a(i);
>    y(i) = length(find(b <= a1));
> end
> a= [1;1;2;3;4;5;7;9;3]
> b=[ 1;2;3;4;1;2;3;3;3;4;1;1;2;3;4]
> y= [4;4;7;12;15;15;15;15;12]
> This works fine with small vectors, but I want to do this with very large vectors.  Is there any way to do this in Matlab without using the For Loop?
> Any help would be appreciated.

This do not require to duplicate in 2D and takes less RAM.
[ua trast I]=unique(a);

You need to check about the correctness with "<=" and "<" of the code. If it does not meet the comparison requirement, work on reverse-sign arrays.