http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462
MATLAB Central Newsreader  how many times repeat a number in an array??
Feed for thread: how many times repeat a number in an array??
enus
©19942014 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Mon, 30 Mar 2009 02:27:01 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#638558
Hoi Wong
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gg1jpt$eja$1@fred.mathworks.com>...<br>
> "Maria " <mariaki16@hotmail.com> wrote in message <gg1cbq$9gl$1@fred.mathworks.com>...<br>
> > what inputs doi have to put in accumarray and in histc in the histc help i found this:<br>
> > <br>
> > N = HISTC(X,EDGES), for vector X, counts the number of values in X<br>
> > that fall between the elements in the EDGES vector (which must contain<br>
> > monotonically nondecreasing values). N is a LENGTH(EDGES) vector<br>
> > containing these counts. <br>
> > <br>
> > what the eges should be???<br>
> <br>
> 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.<br>
> <br>
> 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.<br>
> <br>
> Roger Stafford<br>
<br>
Thanks Roger! I've never given that much thought to the extended parameters for find(), sort() and a 5argument 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)<br>
<br>
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 nonunique deletion list. Turns out that your 8line solution is the fastest of all as I expected (because they are all builtin functions). Simple test is the matrix mentioned in my first post, and the second data set was captured from my project.<br>
<br>
Here's the link to all of your algorithms and mine as well. jengaMatrixSpeedTest tests them all and generate the report below:<br>
<br>
Does all algorithm give the same result for the simple test? true<br>
<br>
Is the test matrices cardinal? true<br>
Cardinality preserved? true<br>
Is the deletion list unique? false<br>
Roger: 0.00110589<br>
Bruno1: 0.00870681<br>
Bruno2: 0.02111930<br>
Bruno4: 0.00462781<br>
Bruno5: 0.00282878<br>
Does all algorithm give the same result for the stress test (with nonunique deletion items)? true<br>
Cardinality preserved? true<br>
<br>
Hoi: 110.50091451<br>
Roger: 0.00098781<br>
Bruno1: 0.00648331<br>
Bruno2: 0.00672234<br>
Bruno4: 0.00160589<br>
Bruno5: 0.00117171<br>
Does all algorithm give the same result for the stress test (with unique deletion items)? true<br>
Cardinality preserved? true

Mon, 30 Mar 2009 02:32:01 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#638560
Hoi Wong
"Hoi Wong" <wonghoi.ee@gmailNOSPAM.com> wrote in message <gqpall$2g8$1@fred.mathworks.com>...<br>
> "Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gg1jpt$eja$1@fred.mathworks.com>...<br>
> > "Maria " <mariaki16@hotmail.com> wrote in message <gg1cbq$9gl$1@fred.mathworks.com>...<br>
> > > what inputs doi have to put in accumarray and in histc in the histc help i found this:<br>
> > > <br>
> > > N = HISTC(X,EDGES), for vector X, counts the number of values in X<br>
> > > that fall between the elements in the EDGES vector (which must contain<br>
> > > monotonically nondecreasing values). N is a LENGTH(EDGES) vector<br>
> > > containing these counts. <br>
> > > <br>
> > > what the eges should be???<br>
> > <br>
> > 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.<br>
> > <br>
> > 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.<br>
> > <br>
> > Roger Stafford<br>
> <br>
> Thanks Roger! I've never given that much thought to the extended parameters for find(), sort() and a 5argument 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)<br>
> <br>
> 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 nonunique deletion list. Turns out that your 8line solution is the fastest of all as I expected (because they are all builtin functions). Simple test is the matrix mentioned in my first post, and the second data set was captured from my project.<br>
> <br>
> Here's the link to all of your algorithms and mine as well. jengaMatrixSpeedTest tests them all and generate the report below:<br>
> <br>
> Does all algorithm give the same result for the simple test? true<br>
> <br>
> Is the test matrices cardinal? true<br>
> Cardinality preserved? true<br>
> Is the deletion list unique? false<br>
> Roger: 0.00110589<br>
> Bruno1: 0.00870681<br>
> Bruno2: 0.02111930<br>
> Bruno4: 0.00462781<br>
> Bruno5: 0.00282878<br>
> Does all algorithm give the same result for the stress test (with nonunique deletion items)? true<br>
> Cardinality preserved? true<br>
> <br>
> Hoi: 110.50091451<br>
> Roger: 0.00098781<br>
> Bruno1: 0.00648331<br>
> Bruno2: 0.00672234<br>
> Bruno4: 0.00160589<br>
> Bruno5: 0.00117171<br>
> Does all algorithm give the same result for the stress test (with unique deletion items)? true<br>
> Cardinality preserved? true<br>
<br>
Oops....sorry. I replied to the wrong thread

Wed, 19 Nov 2008 01:29:02 +0000
how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#611697
Maria
i have a function that gets from the user a random Array.by using the unique function i have a unique list with the arguments of the vector.with out using loop how do i find the times which a number is repeat in the array<br>
<br>
Any help??

Wed, 19 Nov 2008 01:51:02 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#611701
Roger Stafford
"Maria " <mariaki16@hotmail.com> wrote in message <gfvq4u$goe$1@fred.mathworks.com>...<br>
> i have a function that gets from the user a random Array.by using the unique function i have a unique list with the arguments of the vector.with out using loop how do i find the times which a number is repeat in the array<br>
> <br>
> Any help??<br>
<br>
Check on the function 'histc'.<br>
<br>
Roger Stafford

Wed, 19 Nov 2008 02:19:02 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#611705
Maria
can you explane me little the srtucture of histc becouse i don't understand it from the help ?

Wed, 19 Nov 2008 02:48:01 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#611708
Roger Stafford
"Maria " <mariaki16@hotmail.com> wrote in message <gfvt2m$hmp$1@fred.mathworks.com>...<br>
> can you explane me little the srtucture of histc becouse i don't understand it from the help ?<br>
<br>
Hint: What interesting use can you make of the monotonically increasing output of 'unique'?<br>
<br>
Roger Stafford

Wed, 19 Nov 2008 04:00:04 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#611715
Roger Stafford
"Maria " <mariaki16@hotmail.com> wrote in message <gfvq4u$goe$1@fred.mathworks.com>...<br>
> i have a function that gets from the user a random Array.by using the unique function i have a unique list with the arguments of the vector.with out using loop how do i find the times which a number is repeat in the array<br>
> <br>
> Any help??<br>
<br>
An alternative and possbily superior hint is to use the third output argument of 'unique' in the 'accumarray' function rather than doing 'histc'. This has the advantage of requiring only one sort operation altogether.<br>
<br>
Roger Stafford

Wed, 19 Nov 2008 15:46:02 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#611824
Maria
"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <gg0304$g8i$1@fred.mathworks.com>...<br>
> "Maria " <mariaki16@hotmail.com> wrote in message <gfvq4u$goe$1@fred.mathworks.com>...<br>
> > i have a function that gets from the user a random Array.by using the unique function i have a unique list with the arguments of the vector.with out using loop how do i find the times which a number is repeat in the array<br>
> > <br>
> > Any help??<br>
> <br>
> An alternative and possbily superior hint is to use the third output argument of 'unique' in the 'accumarray' function rather than doing 'histc'. This has the advantage of requiring only one sort operation altogether.<br>
> <br>
> Roger Stafford<br>
<br>
<br>
<br>
what inputs doi have to put in accumarray and in histc in the histc help i found this:<br>
<br>
N = HISTC(X,EDGES), for vector X, counts the number of values in X<br>
that fall between the elements in the EDGES vector (which must contain<br>
monotonically nondecreasing values). N is a LENGTH(EDGES) vector<br>
containing these counts. <br>
<br>
what the eges should be???

Wed, 19 Nov 2008 17:53:01 +0000
Re: how many times repeat a number in an array??
http://www.mathworks.com/matlabcentral/newsreader/view_thread/239462#611859
Roger Stafford
"Maria " <mariaki16@hotmail.com> wrote in message <gg1cbq$9gl$1@fred.mathworks.com>...<br>
> what inputs doi have to put in accumarray and in histc in the histc help i found this:<br>
> <br>
> N = HISTC(X,EDGES), for vector X, counts the number of values in X<br>
> that fall between the elements in the EDGES vector (which must contain<br>
> monotonically nondecreasing values). N is a LENGTH(EDGES) vector<br>
> containing these counts. <br>
> <br>
> what the eges should be???<br>
<br>
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.<br>
<br>
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.<br>
<br>
Roger Stafford