Path: news.mathworks.com!not-for-mail
From: "Hoi Wong" <wonghoi.ee@gmailNOSPAM.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how many times repeat a number in an array??
Date: Mon, 30 Mar 2009 02:27:01 +0000 (UTC)
Organization: Stanford University
Lines: 44
Message-ID: <gqpall$2g8$1@fred.mathworks.com>
References: <gfvq4u$goe$1@fred.mathworks.com> <gg0304$g8i$1@fred.mathworks.com> <gg1cbq$9gl$1@fred.mathworks.com> <gg1jpt$eja$1@fred.mathworks.com>
Reply-To: "Hoi Wong" <wonghoi.ee@gmailNOSPAM.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1238380021 2568 172.30.248.35 (30 Mar 2009 02:27:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 30 Mar 2009 02:27:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 742078
Xref: news.mathworks.com comp.soft-sys.matlab:528573


"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gg1jpt$eja$1@fred.mathworks.com>...
> "Maria " <mariaki16@hotmail.com> wrote in message <gg1cbq$9gl$1@fred.mathworks.com>...
> > what inputs doi have to put in accumarray and in histc in the histc help i found this:
> > 
> > N = HISTC(X,EDGES), for vector X, counts the number of values in X
> >     that fall between the elements in the EDGES vector (which must contain
> >     monotonically non-decreasing values).  N is a LENGTH(EDGES) vector
> >     containing these counts. 
> > 
> > what the eges should be???
> 
>   Maria, I will answer your questions this way.  If you make a careful study of what the matlab functions 'histc' and/or 'accumarray' are intended to accomplish, then you will almost automatically realize what kind of inputs they require to solve your particular problem.  This will probably require some experimentation on your part in the use of those functions in order to attain such an understanding.
> 
>   This is the way one best learns to use Matlab.  Being given complete solutions without such an understanding is definitely NOT the right way since it leaves one unprepared for other problems.
> 
> Roger Stafford

Thanks Roger! I've never given that much thought to the extended parameters for find(), sort() and a 5-argument use for sparse() though I've been using them for a while (sparse is quite new to me though. I'm developing a sparse_cell class/dataType and jengaMatrix is a piece of the puzzle)

My first algorithm was embarassing.......it's complicated, uses cellfun, sum, and runs 100000 times slower than any of yours, and it does not work for non-unique deletion list. Turns out that your 8-line solution is the fastest of all as I expected (because they are all built-in functions). Simple test is the matrix mentioned in my first post, and the second data set was captured from my project.

Here's the link to all of your algorithms and mine as well. jengaMatrixSpeedTest tests them all and generate the report below:

Does all algorithm give the same result for the simple test? true
---------------------------------------------------------------
Is the test matrices cardinal? true
Cardinality preserved? true
Is the deletion list unique? false
Roger:  0.00110589
Bruno1: 0.00870681
Bruno2: 0.02111930
Bruno4: 0.00462781
Bruno5: 0.00282878
Does all algorithm give the same result for the stress test (with non-unique deletion items)? true
Cardinality preserved? true
---------------------------------------------------------------
Hoi:  110.50091451
Roger:  0.00098781
Bruno1: 0.00648331
Bruno2: 0.00672234
Bruno4: 0.00160589
Bruno5: 0.00117171
Does all algorithm give the same result for the stress test (with unique deletion items)? true
Cardinality preserved? true