Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: vertorize a loop
Date: Thu, 2 Jun 2011 23:56:04 +0000 (UTC)
Organization: Xoran Technologies
Lines: 22
Message-ID: <is97uk$m3m$1@newscl01ah.mathworks.com>
References: <is8sko$moh$1@newscl01ah.mathworks.com> <is8t9c$oml$1@newscl01ah.mathworks.com> <is8ud0$ruu$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1307058964 22646 172.30.248.46 (2 Jun 2011 23:56:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 2 Jun 2011 23:56:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1440443
Xref: news.mathworks.com comp.soft-sys.matlab:729975

"Gareth Lennox" <celtlen@yahoo.co.uk> wrote in message <is8ud0$ruu$1@newscl01ah.mathworks.com>...
>
> x1 = [1 4
>          3 4
>          3 5]
> 
> and then the code would produce
> 
> x2 = [1 4 5;
>          1 4 6;
>          3 4 5;
>          3 4 6;
>          3 5 6]
>   
> Basically, for each iteration, the feasible solutions would be extended to produce all solutions with one more variable.
======================

It's not clear from your example what range of values the appended variable is supposed to be able to take on, but for the above transition from x1 to x2, the following would work:

 [J,I]=ndgrid(5:6, 1:length(x1));
 x2=[x1(I(:),:), J(:)];
x2=x2(x2(:,end-1)<x2(:,end),:)