From: Joshua Carmichael on 14 Mar 2010 20:16 chariya peterson <chariya(a)kong.gsfc.nasa.gov> wrote in message <35D363FD.B308740C(a)kong.gsfc.nasa.gov>... > This is a multi-part message in MIME format. > --------------3F72E903FF68C8C5D4D0D7BA > Content-Type: text/html; charset=us-ascii > Content-Transfer-Encoding: 7bit > > <HTML> > Hi, > <BR>Sorry for duplicate post. The original post was under the wrong > subject. > > <P>I just posted a question about cell structure. But my news server > is kind of slow. I found one solution before the original question > appears. Let me restate the > <BR>problem: > > <P>Given a finite set, anom, (represented by a cell array). lds is > a function that > <BR>generates the power set of anon. So the output of lds (hyp) should > also be a cell > <BR>array, each of whose cell is a cell (with no subcell). > > <P>Here is a solution: > > <P>function hyp=lds(anom) > <BR>x=size(anom); > <BR>hyp={}; > <BR>for i = 1:x(2) > <BR> hyp2={anom{i}}; > <BR> for j = 1:2^(i-1)-1 > <BR> n=size(hyp{j}); > <BR> p={}; z={}; > <BR> for k =1:n(2) > <BR> z{1}=deal(hyp{j}{k}) > <BR> p=[p,z] > <BR> end > <BR> y = {[p {deal(anom{i}{:})}]} > <BR> hyp2=[hyp2, y] > <BR> end > <BR> hyp=[hyp, hyp2] > <BR>end > <BR>hyp=[hyp, {{''}}] > <BR>return > <BR> > <BR> > <BR>There must be a better way to do this. Is there ? > <BR>chariya > <BR> > <BR> > <BR> </HTML> > > --------------3F72E903FF68C8C5D4D0D7BA > Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf" > Content-Transfer-Encoding: 7bit > Content-Description: Card for Chariya Peterson > Content-Disposition: attachment; filename="vcard.vcf" > > begin: vcard > fn: Chariya Peterson > n: Peterson;Chariya > org: Computer Sciences Corp > email;internet: chariya(a)kong.gsfc.nasa.gov > x-mozilla-cpt: ;0 > x-mozilla-html: TRUE > version: 2.1 > end: vcard > > > --------------3F72E903FF68C8C5D4D0D7BA-- > Did anyone ever respond to this thread with an answer? I have been searching for a Matlab function to compute power sets, and this is the one entry I could find. I used lds provided by the author and it worked perfectly; the solution is elegant, and I don't see an obvious improvement.
From: Jos (10584) on 15 Mar 2010 02:53 "Joshua Carmichael" <joshuadc(a)u.washington.edu> wrote in message <hnju85$1o$1(a)fred.mathworks.com>... > chariya peterson <chariya(a)kong.gsfc.nasa.gov> wrote in message <35D363FD.B308740C(a)kong.gsfc.nasa.gov>... > Did anyone ever respond to this thread with an answer? I have been searching for a Matlab function to compute power sets, and this is the one entry I could find. I used lds provided by the author and it worked perfectly; the solution is elegant, and I don't see an obvious improvement. Take a look at my NCHOOSE function available on the File Exchange, which is fast and vectorized. NCHOOSE almost returns the powerset, that is, you have to add the empty set explicitly S = {'a', 1:4 , {'c1',123}} PowerSet = nchoose(S) ; PowerSet(end+1) = [] % add empty set http://www.mathworks.com/matlabcentral/fileexchange/20011 hth Jos
From: Joshua Carmichael on 18 Mar 2010 23:03 "Jos (10584) " <#10584(a)fileexchange.com> wrote in message <hnklge$nvg$1(a)fred.mathworks.com>... > "Joshua Carmichael" <joshuadc(a)u.washington.edu> wrote in message <hnju85$1o$1(a)fred.mathworks.com>... > > chariya peterson <chariya(a)kong.gsfc.nasa.gov> wrote in message <35D363FD.B308740C(a)kong.gsfc.nasa.gov>... > > > Did anyone ever respond to this thread with an answer? I have been searching for a Matlab function to compute power sets, and this is the one entry I could find. I used lds provided by the author and it worked perfectly; the solution is elegant, and I don't see an obvious improvement. > > Take a look at my NCHOOSE function available on the File Exchange, which is fast and vectorized. NCHOOSE almost returns the powerset, that is, you have to add the empty set explicitly > > S = {'a', 1:4 , {'c1',123}} > PowerSet = nchoose(S) ; > PowerSet(end+1) = [] % add empty set > > http://www.mathworks.com/matlabcentral/fileexchange/20011 > > hth > Jos Thanks, I will download it. I don't need the empty set anyways :-) josh
|
Pages: 1 Prev: parfor performance problem Next: storing vectors of multiple lengths in for loop |