Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Logical Rules
Date: Thu, 13 Sep 2007 17:47:43 +0000 (UTC)
Organization: Princeton University
Lines: 51
Message-ID: <fcbt3v$pkb$1@fred.mathworks.com>
References: <fcbpn6$eo0$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1189705663 26251 172.30.248.35 (13 Sep 2007 17:47:43 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Sep 2007 17:47:43 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 185640
Xref: news.mathworks.com comp.soft-sys.matlab:428405



"Christopher Mouton" <mouton.no.spam@caltech.edu> wrote in
message <fcbpn6$eo0$1@fred.mathworks.com>...
> I am trying to see if Matlab has a toolbox for something 
> like this, or where I might look for ideas on how to 
> efficiently solve the following
> 
> A{1}=[1,2]
> A{2}=[2,3]
> A{3}=[1,3]
> A{4}=[1,2,3,4]
> 
> This reads:
> 
> Position 1 can be 1 or 2
> Position 2 can be 2 or 3
> Position 3 can be 1 or 3
> Position 4 can be 1, 2, 3 or 4
> 
> Given that each number can only be used once, we know that 
> Position 4 must be 4.
> 
> So my question is, how could I perform such logic in a 
> general way? Any ideas where I should look?
> 
> Thanks so much.

The most straightforward way would be to just form all
combinations possible, then throw out any that don't meet
the uniqueness criteria.

A{1}=[1,2];
A{2}=[2,3];
A{3}=[1,3];
A{4}=[1,2,3,4];

combos = [];
for a = A{1}
    for b = A{2}
        for c = A{3}
            for d = A{4}
                temp = [a b c d];
                if length(unique(temp)) == 4
                    combos = [combos;temp];
                end      
            end
        end
    end
end


-Kelly