Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: genvarname doesn't work
Date: Sun, 27 Dec 2009 20:27:03 +0000 (UTC)
Organization: University of Waterloo
Lines: 27
Message-ID: <hh8fun$k71$1@fred.mathworks.com>
References: <h37t8i$6kh$1@fred.mathworks.com> <op.uwu54zbja5ziv5@uthamaa.dhcp.mathworks.com> <h389nd$omc$1@fred.mathworks.com> <h38a6i$pud$1@fred.mathworks.com> <h38c66$5f9$1@fred.mathworks.com> <h38dor$hld$1@fred.mathworks.com> <h3e536$8q4$1@fred.mathworks.com> <h4apo6$143$1@fred.mathworks.com> <h4cia8$cjb$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1261945623 20705 172.30.248.38 (27 Dec 2009 20:27:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 27 Dec 2009 20:27:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1646679
Xref: news.mathworks.com comp.soft-sys.matlab:595038


"Steven Lord" <slord@mathworks.com> wrote in message > Yes.
> 
> A = 'AB';
> nvariables = 5;
> clear c
> [c{1:nvariables}] = ndgrid(A);
> A3 = repmat(' ', numel(c{1}), nvariables);
> for k = 1:nvariables
>     A3(:, k) = c{k}(:);
> end
> 
> Or, if you don't like comma-separated lists and don't mind the combinations 
> being in a little different order:
> 
> A = 'ABC';
> nvariables = 5;
> len = numel(A);
> numCombs = len^nvariables;
> ind = dec2base(0:(numCombs-1), len);
> A(ind-'0'+1)
----------------------------------------------------------

Steve Lord you are a genius!

This was very helpful, although it's probably going to take me a long time to decipher what you're doing.

Only an expert like you could come up with something that clever!