Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: How can I do this in MATLAB? (Possibilities)
Date: Sat, 31 Jan 2009 15:21:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 64
Message-ID: <gm1q8t$5ap$1@fred.mathworks.com>
References: <gm1mkl$eq0$1@fred.mathworks.com> <4034274c-ad64-40f0-a46d-7b8fbedb3094@g1g2000pra.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1233415261 5465 172.30.248.38 (31 Jan 2009 15:21:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 31 Jan 2009 15:21:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1477385
Xref: news.mathworks.com comp.soft-sys.matlab:515136


Thanks for the reply and no, it's not homework; it's part of a larger algorithm I'm working on.
Anyway I figured it out. It's a bit messy but good enough for my application.

function sS=eiiy(var,ord)
co=zeros(1,var);
c=1;
CC=zeros(1,var);
for h=1:ord;
	for k=1:var
		CC(c,:)=co;
		CC(c,k)=CC(c,k)+h;		
		for g=[1:k-1 k+1:var]
			for p=0:h
				CC(c,g)=p;
				CC(c+1,:)=CC(c,:);				
				c=c+1;
			end
			CC(c,:)=co;
			CC(c,k)=CC(c,k)+h;
		end
	end
end
CCR=unique(CC,'rows');
qr=sum(CCR,2);
sS=CCR(qr<=ord,:);
end

Example:
>> eiiy(3,4)

ans =

     0     0     1
     0     0     2
     0     0     3
     0     0     4
     0     1     0
     0     1     1
     0     1     2
     0     1     3
     0     2     0
     0     2     1
     0     2     2
     0     3     0
     0     3     1
     0     4     0
     1     0     0
     1     0     1
     1     0     2
     1     0     3
     1     1     0
     1     2     0
     1     3     0
     2     0     0
     2     0     1
     2     0     2
     2     1     0
     2     2     0
     3     0     0
     3     0     1
     3     1     0
     4     0     0

I think it works for all cases.