<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886</link>
    <title>MATLAB Central Newsreader - eliminate identical raws</title>
    <description>Feed for thread: eliminate identical raws</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sun, 17 Feb 2008 07:16:03 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415583</link>
      <author>Roger Stafford</author>
      <description>"us " &amp;lt;us@neurol.unizh.ch&amp;gt; wrote in message &amp;lt;fp8c8e$ami&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
\&amp;gt; YES... i KNEW one of the very CSSM seniors( :-) ) would ..........&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;There is another aspect of the above (corrected) solution #1 that bothers &lt;br&gt;
me, Urs, though I admittedly don't have a better alternative ready to put &lt;br&gt;
forth.  With some of the larger numbers of elements in array 'a', one comes &lt;br&gt;
up with some discouragingly large arrays for 'x' that have to be greatly &lt;br&gt;
reduced in size.  Suppose we have a = [1 2 3 4 5 6 7 7 7 7 7 7].  Then the &lt;br&gt;
number of rows in x before it is reduced would be 7^12, which is a hefty &lt;br&gt;
1.38e10 rows, whereas the number of valid combinations is only 12!/6!, &lt;br&gt;
which is a very much smaller 6.65e5 rows.  This is a very severe rejection &lt;br&gt;
process with only one survivor in every twenty thousand.  In this case, even &lt;br&gt;
'perms' gives rise to a smaller 12!, which would be only 4.8e8 rows.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;My intuition tells me that for a robust, general solution to this problem &lt;br&gt;
suitable for all cases for which there is a reasonable number of rows in the &lt;br&gt;
final solution, it would be best to use an algorithm which does not require &lt;br&gt;
that any combinations be rejected later on, even if much despised for-loops &lt;br&gt;
have to be used.  I envision it as a generalization and adaptation of the &lt;br&gt;
algorithm which is apparently used in the 'nchoosek' function.  John D'Errico &lt;br&gt;
has written 'loopchoose', which if I understand it correctly, creates only valid &lt;br&gt;
combinations successively each time it takes a step, with none needing to be &lt;br&gt;
rejected.  The idea would be to generalize such methods to any number of &lt;br&gt;
distinct values in the array rather than just the two which, in effect, &lt;br&gt;
'nchoosek' and 'loopchoose' deal with.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 17 Feb 2008 04:13:02 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415574</link>
      <author>us</author>
      <description>"Roger Stafford":&lt;br&gt;
&amp;lt;SNIP high noon...&lt;br&gt;
&lt;br&gt;
YES... i KNEW one of the very CSSM seniors( :-) ) would &lt;br&gt;
hook on to this (obvious) weakness the moment i clicked the &lt;br&gt;
&amp;lt;post message&amp;gt; button... (seriously)&lt;br&gt;
&lt;br&gt;
a more proper solution looks like the following snipplet - &lt;br&gt;
and reveals (once more) that one solution is not &lt;br&gt;
necessarily good for life...&lt;br&gt;
&lt;br&gt;
us&lt;br&gt;
&lt;br&gt;
put this into a file, eg, &amp;lt;foo.m&amp;gt;&lt;br&gt;
&lt;br&gt;
function foo(a)&lt;br&gt;
tic;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;au=unique(a);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;na=numel(a);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=cell(na,1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ap=repmat({au},1,na);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[x{1:na,1}]=ndgrid(ap{:});&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=reshape(cat(na+1,x{:}),[],na);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xs=whos('x');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=x(:,end:-1:1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=x(cellfun(@(x) isequal(x,sort(a)),...&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;num2cell(sort(x,2),2),'uni',true),:);&lt;br&gt;
toc&lt;br&gt;
% comparison with a more traditional solution&lt;br&gt;
tic;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p=perms(a);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ps=whos('p');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pu=unique(p,'rows');&lt;br&gt;
toc&lt;br&gt;
% - max temp sizes and &amp;lt;equal&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp([xs.bytes;ps.bytes;isequal(x,pu)]);&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
% results of various runs on a wintel os&lt;br&gt;
% c2.2*2.4/2gb/winvista.sp1/r2008a&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo([3,3,3,6,6,3,3,7]);&lt;br&gt;
% Elapsed time is 0.081403 seconds. OK&lt;br&gt;
% Elapsed time is 0.137693 seconds.&lt;br&gt;
%       419904&lt;br&gt;
%      2580480&lt;br&gt;
%            1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo(1:4)&lt;br&gt;
% Elapsed time is 0.029856 seconds. OK&lt;br&gt;
% Elapsed time is 0.058627 seconds.&lt;br&gt;
%         8192&lt;br&gt;
%          768&lt;br&gt;
%            1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo(1:7);&lt;br&gt;
% Elapsed time is 10.774500 seconds. !!!!!&lt;br&gt;
% Elapsed time is 0.009430 seconds.&lt;br&gt;
%     46118408&lt;br&gt;
%       282240&lt;br&gt;
%           1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo([1,1,1,1,1,1,1,1,1]);&lt;br&gt;
% Elapsed time is 0.004127 seconds. !!!!!&lt;br&gt;
% Elapsed time is 1.924781 seconds.&lt;br&gt;
%           72 !!!!!&lt;br&gt;
%     26127360&lt;br&gt;
%            1&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;foo([1,1,1,1,1,2,1,1,1]);&lt;br&gt;
% Elapsed time is 0.072507 seconds.&lt;br&gt;
% Elapsed time is 2.280715 seconds. !!!!!&lt;br&gt;
%        36864&lt;br&gt;
%     26127360&lt;br&gt;
%            1&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sun, 17 Feb 2008 03:08:01 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415572</link>
      <author>Roger Stafford</author>
      <description>"us " &amp;lt;us@neurol.unizh.ch&amp;gt; wrote in message &amp;lt;fp7991$656&lt;br&gt;
$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; vladimir:&lt;br&gt;
&amp;gt; &amp;lt;SNIP combinatorial evergreen...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; one of the other many solutions is outlined below &lt;br&gt;
&amp;gt; (including the comparison with a more traditional one as &lt;br&gt;
&amp;gt; shown by others)...&lt;br&gt;
&amp;gt; timing on a wintel c2.2*2.4/2gb/winxp.sp2/r2008a&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; us&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; % the data&lt;br&gt;
&amp;gt;      a=[3,3,3,6,6,3,3,7];&lt;br&gt;
&amp;gt; % the engine&lt;br&gt;
&amp;gt; tic;&lt;br&gt;
&amp;gt;      as=sum(a);&lt;br&gt;
&amp;gt;      au=unique(a);&lt;br&gt;
&amp;gt;      na=numel(a);&lt;br&gt;
&amp;gt;      nu=numel(au);&lt;br&gt;
&amp;gt;      x=cell(na,1);&lt;br&gt;
&amp;gt;      ap=repmat({au},1,na);&lt;br&gt;
&amp;gt;      [x{1:na,1}]=ndgrid(ap{:});&lt;br&gt;
&amp;gt;      x=reshape(cat(na+1,x{:}),[],na);&lt;br&gt;
&amp;gt;      xs=whos('x');&lt;br&gt;
&amp;gt;      x=x(sum(x,2)==as,:);&lt;br&gt;
&amp;gt;      x=x(:,end:-1:1);&lt;br&gt;
&amp;gt; toc&lt;br&gt;
&amp;gt; % comparison with a more traditional solution&lt;br&gt;
&amp;gt; tic;&lt;br&gt;
&amp;gt;      p=perms(a);&lt;br&gt;
&amp;gt;      ps=whos('p');&lt;br&gt;
&amp;gt;      pu=unique(p,'rows');&lt;br&gt;
&amp;gt; toc&lt;br&gt;
&amp;gt; % - max temp sizes and &amp;lt;equal&amp;gt;&lt;br&gt;
&amp;gt;      disp([xs.bytes;ps.bytes;isequal(x,pu)]);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; %{&lt;br&gt;
&amp;gt; Elapsed time is 0.051470 seconds. % sol #1&lt;br&gt;
&amp;gt; Elapsed time is 0.182210 seconds. % sol #2&lt;br&gt;
&amp;gt;       419904 % &amp;lt;- x max size&lt;br&gt;
&amp;gt;      2580480 % &amp;lt;- p max size&lt;br&gt;
&amp;gt;            1 % &amp;lt;- res are equal&lt;br&gt;
&amp;gt; %}&lt;br&gt;
----------&lt;br&gt;
&amp;nbsp;&amp;nbsp;I have serious doubts about the above line&lt;br&gt;
&lt;br&gt;
&amp;nbsp;x=x(sum(x,2)==as,:);&lt;br&gt;
&lt;br&gt;
in your solution #1, Urs.  Suppose that array a = [1,2,3,4].  Presumably, at the &lt;br&gt;
time you do the 'whos' command, 'x' will have 4^4 = 256 rows.  Among its &lt;br&gt;
various rows will appear [1,1,4,4], [1,3,3,3], and various rearrangements of &lt;br&gt;
these, all of which have the as = 10 sum required by the above line.  Won't &lt;br&gt;
they slip through into your final x?  I would predict that 'x' in this case will &lt;br&gt;
have ten extra unwanted rows above the expected twenty four.  I think you &lt;br&gt;
need to make your rejection criterion more exacting than a simple sum of the &lt;br&gt;
original elements.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 18:16:01 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415508</link>
      <author>us</author>
      <description>vladimir:&lt;br&gt;
&amp;lt;SNIP combinatorial evergreen...&lt;br&gt;
&lt;br&gt;
one of the other many solutions is outlined below &lt;br&gt;
(including the comparison with a more traditional one as &lt;br&gt;
shown by others)...&lt;br&gt;
timing on a wintel c2.2*2.4/2gb/winxp.sp2/r2008a&lt;br&gt;
&lt;br&gt;
us&lt;br&gt;
&lt;br&gt;
% the data&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a=[3,3,3,6,6,3,3,7];&lt;br&gt;
% the engine&lt;br&gt;
tic;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;as=sum(a);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;au=unique(a);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;na=numel(a);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nu=numel(au);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=cell(na,1);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ap=repmat({au},1,na);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[x{1:na,1}]=ndgrid(ap{:});&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=reshape(cat(na+1,x{:}),[],na);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;xs=whos('x');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=x(sum(x,2)==as,:);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;x=x(:,end:-1:1);&lt;br&gt;
toc&lt;br&gt;
% comparison with a more traditional solution&lt;br&gt;
tic;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;p=perms(a);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ps=whos('p');&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;pu=unique(p,'rows');&lt;br&gt;
toc&lt;br&gt;
% - max temp sizes and &amp;lt;equal&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;disp([xs.bytes;ps.bytes;isequal(x,pu)]);&lt;br&gt;
&lt;br&gt;
%{&lt;br&gt;
Elapsed time is 0.051470 seconds. % sol #1&lt;br&gt;
Elapsed time is 0.182210 seconds. % sol #2&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;419904 % &amp;lt;- x max size&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2580480 % &amp;lt;- p max size&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1 % &amp;lt;- res are equal&lt;br&gt;
%}&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 16:58:02 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415499</link>
      <author>Roger Stafford</author>
      <description>"Roger Stafford" &amp;lt;ellieandrogerxyzzy@mindspring.com.invalid&amp;gt; wrote in &lt;br&gt;
message &amp;lt;fp710n$32a$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; ..........&lt;br&gt;
&amp;gt;   A note of caution.  Unfortunately I don't have 'nchoosek' to experiment &lt;br&gt;
with &lt;br&gt;
&amp;gt; on my system, and there is one aspect of it that is worrisome.  In their &lt;br&gt;
&amp;gt; documentation MathWorks gives the same "practical" limit on the use of &lt;br&gt;
&amp;gt; 'nchoosek' as it does for 'perms', namely that n ought not to exceed 15.  &lt;br&gt;
One &lt;br&gt;
&amp;gt; would think that 'nchoosek' ought to be able to deal with considerably &lt;br&gt;
larger &lt;br&gt;
&amp;gt; values of n than this without encountering the difficulties of 'perms'.  This &lt;br&gt;
&amp;gt; would appear to suggest that perhaps 'nchoosek' also does something &lt;br&gt;
crude &lt;br&gt;
&amp;gt; like a 'perms' operation followed by a call to 'unique', in which case there &lt;br&gt;
&amp;gt; would be no particular advantage to using 'nchoosek' as given above.  A &lt;br&gt;
huge &lt;br&gt;
&amp;gt; array would be created in either case.  Can anyone in this group tell me if &lt;br&gt;
that &lt;br&gt;
&amp;gt; is true?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
---------&lt;br&gt;
&amp;nbsp;&amp;nbsp;Vladimir, I've just been reading John D'Errico's description of his loop &lt;br&gt;
version of 'nchoosek' at&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;lt;&lt;a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?"&gt;http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?&lt;/a&gt;&lt;br&gt;
objectId=13276&amp;gt;&lt;br&gt;
&lt;br&gt;
which he calls 'loopchoose'.  In it he mentions that the call nchoosek(1:20,10) &lt;br&gt;
takes only 18.35 seconds on his computer.  That puts to rest the worries I &lt;br&gt;
mentioned earlier.  If it were to first create a 'perms' type output, it would &lt;br&gt;
generate 20! = 2.4e20 rows, which clearly could not have happened in 18.35 &lt;br&gt;
seconds nor in any computer known to man.  So you can forget what I said in &lt;br&gt;
that last paragraph.  MathWorks needs to correct their documentation.  You &lt;br&gt;
should be able to use 'nchoosek' effectively for the larger values of p and q.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;For more than two different numbers in your original array, let's say p of &lt;br&gt;
one, q of another, r of another, etc., the total number of distinct rows would &lt;br&gt;
be:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;(p+q+r+...)/(p!*q!*r!*...) .&lt;br&gt;
&lt;br&gt;
I think an iterative process could be devised that would solve your problem in &lt;br&gt;
such a case with multiple calls on 'nchoosek'.  However, I couldn't tell from &lt;br&gt;
your question just how general a problem you are faced with.&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 16:29:28 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415494</link>
      <author>Greg Heath</author>
      <description>On Feb 16, 10:55=A0am, "Roger Stafford"&lt;br&gt;
&amp;lt;ellieandrogerxy...@mindspring.com.invalid&amp;gt; wrote:&lt;br&gt;
&amp;gt; vladimir &amp;lt;rus_lo...@comcast.net&amp;gt; wrote in message&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;lt;27823314.1203129850043.JavaMail.jaka...@nitrogen.mathforum.org&amp;gt;...&amp;gt; I hav=&lt;br&gt;
e a probability problem that requires matrix A=3D[1 1 1 2 2] going&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; through perms(A) which gives me many identical rows. How do I eliminate al=&lt;br&gt;
l&lt;br&gt;
&amp;gt; the identical rowa but one? Answer probably is the easy one, but not for a=&lt;br&gt;
&lt;br&gt;
&amp;gt; beginner like myself. Thanks much.&amp;gt; Vladimir T&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; ---------&lt;br&gt;
&amp;gt; =A0 If you have p ones and q twos, the number of different rows would be&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; =A0nCp =3D (p+q)!/(p!*q!)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; where n =3D p+q. =A0In your example, this would be 5C3 =3D 10 out of a tot=&lt;br&gt;
al of 5!&lt;br&gt;
&amp;gt; =3D 120 produced by 'perms'. =A0With such small numbers, using 'perms' fol=&lt;br&gt;
lowed&lt;br&gt;
&amp;gt; by 'unique' to eliminate repetitions, as was suggested by John, is a good&lt;br&gt;
&amp;gt; method.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; =A0 However, for larger values of p and q, this method runs into problems.=&lt;br&gt;
&amp;nbsp;=A0For&lt;br&gt;
&amp;gt; example, if p and q were both equal to 7, then 'perms' would generate an&lt;br&gt;
&amp;gt; array of some 14! =3D 87 billion rows which would then have to be narrowed=&lt;br&gt;
&lt;br&gt;
&amp;gt; down to a much smaller 14C7 =3D 3432 different rows, a rather inefficient&lt;br&gt;
&amp;gt; process even if one had enough memory.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; =A0 This would suggest that one might consider using matlab's 'nchoosek'&lt;br&gt;
&amp;gt; function which creates all possible combinations of p things out of a set =&lt;br&gt;
of n&lt;br&gt;
&amp;gt; things. =A0That is, it directly creates the magic number of nCp different&lt;br&gt;
&amp;gt; combinations with nothing that need be eliminated. =A0One way to use&lt;br&gt;
&amp;gt; 'nchoosek' for this purpose might be the following:&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; =A0n =3D p+q;&lt;br&gt;
&amp;gt; =A0C =3D nchoosek(1:n,p);&lt;br&gt;
&amp;gt; =A0N =3D size(C,1); % (N =3D nCp)&lt;br&gt;
&amp;gt; =A0B =3D repmat(2,N,n); % Start with all twos&lt;br&gt;
&amp;gt; =A0for ix =3D 1:N&lt;br&gt;
&amp;gt; =A0 B(ix,C(ix,:)) =3D 1; % Insert p ones into each row&lt;br&gt;
&amp;gt; =A0end&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Array B would then have the desired result. =A0(Actually this for-loop cou=&lt;br&gt;
ld be&lt;br&gt;
&amp;gt; eliminated using 'sub2ind' appropriately.)&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; =A0 A note of caution. =A0Unfortunately I don't have 'nchoosek' to experim=&lt;br&gt;
ent with&lt;br&gt;
&amp;gt; on my system, and there is one aspect of it that is worrisome. =A0In their=&lt;br&gt;
&lt;br&gt;
&amp;gt; documentation MathWorks gives the same "practical" limit on the use of&lt;br&gt;
&amp;gt; 'nchoosek' as it does for 'perms', namely that n ought not to exceed 15. =&lt;br&gt;
=A0One&lt;br&gt;
&amp;gt; would think that 'nchoosek' ought to be able to deal with considerably lar=&lt;br&gt;
ger&lt;br&gt;
&amp;gt; values of n than this without encountering the difficulties of 'perms'. =&lt;br&gt;
=A0This&lt;br&gt;
&amp;gt; would appear to suggest that perhaps 'nchoosek' also does something crude&lt;br&gt;
&amp;gt; like a 'perms' operation followed by a call to 'unique', in which case the=&lt;br&gt;
re&lt;br&gt;
&amp;gt; would be no particular advantage to using 'nchoosek' as given above. =A0A =&lt;br&gt;
huge&lt;br&gt;
&amp;gt; array would be created in either case. =A0Can anyone in this group tell me=&lt;br&gt;
&amp;nbsp;if that&lt;br&gt;
&amp;gt; is true?&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Roger Stafford&lt;br&gt;
&lt;br&gt;
Neither PERMS or UNIQUE are used in NCHOOSEK. However,&lt;br&gt;
NCHOOSEK calls internal function COMBS which is somehow&lt;br&gt;
defined with a recursive call to itself.&lt;br&gt;
&lt;br&gt;
Hope this helps.&lt;br&gt;
&lt;br&gt;
Greg&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 15:55:03 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415486</link>
      <author>Roger Stafford</author>
      <description>vladimir &amp;lt;rus_lopes@comcast.net&amp;gt; wrote in message &lt;br&gt;
&amp;lt;27823314.1203129850043.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I have a probability problem that requires matrix A=[1 1 1 2 2] going &lt;br&gt;
through perms(A) which gives me many identical rows. How do I eliminate all &lt;br&gt;
the identical rowa but one? Answer probably is the easy one, but not for a &lt;br&gt;
beginner like myself. Thanks much.&lt;br&gt;
&amp;gt; Vladimir T&lt;br&gt;
---------&lt;br&gt;
&amp;nbsp;&amp;nbsp;If you have p ones and q twos, the number of different rows would be&lt;br&gt;
&lt;br&gt;
&amp;nbsp;nCp = (p+q)!/(p!*q!)&lt;br&gt;
&lt;br&gt;
where n = p+q.  In your example, this would be 5C3 = 10 out of a total of 5! &lt;br&gt;
= 120 produced by 'perms'.  With such small numbers, using 'perms' followed &lt;br&gt;
by 'unique' to eliminate repetitions, as was suggested by John, is a good &lt;br&gt;
method.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;However, for larger values of p and q, this method runs into problems.  For &lt;br&gt;
example, if p and q were both equal to 7, then 'perms' would generate an &lt;br&gt;
array of some 14! = 87 billion rows which would then have to be narrowed &lt;br&gt;
down to a much smaller 14C7 = 3432 different rows, a rather inefficient &lt;br&gt;
process even if one had enough memory.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;This would suggest that one might consider using matlab's 'nchoosek' &lt;br&gt;
function which creates all possible combinations of p things out of a set of n &lt;br&gt;
things.  That is, it directly creates the magic number of nCp different &lt;br&gt;
combinations with nothing that need be eliminated.  One way to use &lt;br&gt;
'nchoosek' for this purpose might be the following:&lt;br&gt;
&lt;br&gt;
&amp;nbsp;n = p+q;&lt;br&gt;
&amp;nbsp;C = nchoosek(1:n,p);&lt;br&gt;
&amp;nbsp;N = size(C,1); % (N = nCp)&lt;br&gt;
&amp;nbsp;B = repmat(2,N,n); % Start with all twos&lt;br&gt;
&amp;nbsp;for ix = 1:N&lt;br&gt;
&amp;nbsp;&amp;nbsp;B(ix,C(ix,:)) = 1; % Insert p ones into each row&lt;br&gt;
&amp;nbsp;end&lt;br&gt;
&lt;br&gt;
Array B would then have the desired result.  (Actually this for-loop could be &lt;br&gt;
eliminated using 'sub2ind' appropriately.)&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;A note of caution.  Unfortunately I don't have 'nchoosek' to experiment with &lt;br&gt;
on my system, and there is one aspect of it that is worrisome.  In their &lt;br&gt;
documentation MathWorks gives the same "practical" limit on the use of &lt;br&gt;
'nchoosek' as it does for 'perms', namely that n ought not to exceed 15.  One &lt;br&gt;
would think that 'nchoosek' ought to be able to deal with considerably larger &lt;br&gt;
values of n than this without encountering the difficulties of 'perms'.  This &lt;br&gt;
would appear to suggest that perhaps 'nchoosek' also does something crude &lt;br&gt;
like a 'perms' operation followed by a call to 'unique', in which case there &lt;br&gt;
would be no particular advantage to using 'nchoosek' as given above.  A huge &lt;br&gt;
array would be created in either case.  Can anyone in this group tell me if that &lt;br&gt;
is true?&lt;br&gt;
&lt;br&gt;
Roger Stafford&lt;br&gt;
&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 04:09:02 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415455</link>
      <author>John D'Errico</author>
      <description>vladimir &amp;lt;rus_lopes@comcast.net&amp;gt; wrote in message &lt;br&gt;
&amp;lt;27823314.1203129850043.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I have a probability problem that requires matrix A=[1 1 1 2 2] going through &lt;br&gt;
perms(A) which gives me many identical rows. How do I eliminate all the &lt;br&gt;
identical rowa but one? Answer probably is the easy one, but not for a beginner &lt;br&gt;
like myself. Thanks much.&lt;br&gt;
&amp;gt; Vladimir T&lt;br&gt;
&lt;br&gt;
I don't know if its easy, but the answer is&lt;br&gt;
definitely a "unique" one. &lt;br&gt;
&lt;br&gt;
unique(B,'rows')&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 04:08:05 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415454</link>
      <author>John D'Errico</author>
      <description>vladimir &amp;lt;rus_lopes@comcast.net&amp;gt; wrote in message &lt;br&gt;
&amp;lt;27823314.1203129850043.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I have a probability problem that requires matrix A=[1 1 1 2 2] going through &lt;br&gt;
perms(A) which gives me many identical rows. How do I eliminate all the &lt;br&gt;
identical rowa but one? Answer probably is the easy one, but not for a beginner &lt;br&gt;
like myself. Thanks much.&lt;br&gt;
&amp;gt; Vladimir T&lt;br&gt;
&lt;br&gt;
I don't know if its easy, but the answer is&lt;br&gt;
definitely a "unique" one. &lt;br&gt;
&lt;br&gt;
unique(B,'rows')&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 04:08:03 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415453</link>
      <author>John D'Errico</author>
      <description>vladimir &amp;lt;rus_lopes@comcast.net&amp;gt; wrote in message &lt;br&gt;
&amp;lt;27823314.1203129850043.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I have a probability problem that requires matrix A=[1 1 1 2 2] going through &lt;br&gt;
perms(A) which gives me many identical rows. How do I eliminate all the &lt;br&gt;
identical rowa but one? Answer probably is the easy one, but not for a beginner &lt;br&gt;
like myself. Thanks much.&lt;br&gt;
&amp;gt; Vladimir T&lt;br&gt;
&lt;br&gt;
I don't know if its easy, but the answer is&lt;br&gt;
definitely a "unique" one. &lt;br&gt;
&lt;br&gt;
unique(B,'rows')&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 04:08:02 -0500</pubDate>
      <title>Re: eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415452</link>
      <author>John D'Errico</author>
      <description>vladimir &amp;lt;rus_lopes@comcast.net&amp;gt; wrote in message &lt;br&gt;
&amp;lt;27823314.1203129850043.JavaMail.jakarta@nitrogen.mathforum.org&amp;gt;...&lt;br&gt;
&amp;gt; I have a probability problem that requires matrix A=[1 1 1 2 2] going through &lt;br&gt;
perms(A) which gives me many identical rows. How do I eliminate all the &lt;br&gt;
identical rowa but one? Answer probably is the easy one, but not for a beginner &lt;br&gt;
like myself. Thanks much.&lt;br&gt;
&amp;gt; Vladimir T&lt;br&gt;
&lt;br&gt;
I don't know if its easy, but the answer is&lt;br&gt;
definitely a "unique" one. &lt;br&gt;
&lt;br&gt;
unique(B,'rows')&lt;br&gt;
&lt;br&gt;
HTH,&lt;br&gt;
John&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Sat, 16 Feb 2008 02:43:39 -0500</pubDate>
      <title>eliminate identical raws</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/163886#415448</link>
      <author>vladimir</author>
      <description>I have a probability problem that requires matrix A=[1 1 1 2 2] going through perms(A) which gives me many identical rows. How do I eliminate all the identical rowa but one? Answer probably is the easy one, but not for a beginner like myself. Thanks much.&lt;br&gt;
Vladimir T&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
