Path: news.mathworks.com!not-for-mail 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$1@fred.mathworks.com> References: <gg8c2k$s8d$1@fred.mathworks.com> Reply-To: "Bruno Luong" <b.luong@fogale.findmycountry> 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 1227346502 11840 172.30.248.37 (22 Nov 2008 09:35:02 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sat, 22 Nov 2008 09:35:02 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 390839 Xref: news.mathworks.com comp.soft-sys.matlab:502475 "Gordon " <mloomis@gmail.com> wrote in message <gg8c2k$s8d$1@fred.mathworks.com>... > I’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… > > 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); n=cumsum(histc(b,ua)); y=n(I) 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. Bruno