comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Finding all the possible subsets of a given vector
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Finding all the possible subsets of a given vector [message #81185] Mon, 20 August 2012 13:36
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
On Mon, 20 Aug 2012 12:22:35 -0700 (PDT), MD wrote:

> Hi All,
>
> I have the following question: is there any simple way in IDL which can find all the possible subsets of a vector of n elements starting from subsets with 2 elements until a final subset of n elements (last subset will have all the elements of the given vector). For example:
>
> let A = [1,2, 3, 4] be a given vector. The subsets would be: [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4], [1, 2, 3], [1, 2, 4], [1, 3, 4], [2, 3, 4], [1, 2, 3, 4]. Note that the subsets that have the same elements are assumed equal, although the elements have different sequence: for example [2, 3] and [3, 2] are the same.
>
> Any help is appreciated!
>
> MD

Let n be the number of elements of the given vector a. Then the number
of different subsets is 2^n-1. They can be calculated as follows:

a=[1,2,3,4]
n=n_elements(a)
for i=1,2^n-1 do print,a[where((i/2L^lindgen(n)) mod 2L eq 1L)]

Have fun, Heinz
[Message index]
 
Read Message
Previous Topic: polynomial fitting constrained to be non-decreasing
Next Topic: Re: Obtain all child widgets

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 07:37:43 PDT 2025

Total time taken to generate the page: 0.64195 seconds