Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: genvarname doesn't work
Date: Thu, 23 Jul 2009 22:55:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 36
Message-ID: <h4apo6$143$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>
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 1248389702 1155 172.30.248.38 (23 Jul 2009 22:55:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 23 Jul 2009 22:55:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1646679
Xref: news.mathworks.com comp.soft-sys.matlab:557980


Okay Steven Lord, you have definitely convinced me that there are advantages of not poofing variables into existence, but how could a loop like this be done without poofing variables ??
---------------------------------------------------
A='AB';
z=1;
for a=1:length(A) for b=1:length(A) for c=1:length(A) % for d=... for e=...
            A3(z,1)=A(a);
            A3(z,2)=A(b);
            A3(z,3)=A(c);
% ................. do the same for d, e , up to , let's say n 
            z=z+1; end
            end
        end
---------------------------------------------------

It would take too long to type out "for" and "end"  n times.
The only way I see this being done is something like:

indices={'a' 'b' 'c' 'd' 'e' 'f' 'g' 'h' 'i' 'j' 'k' 'l' 'm' 'n' 'o'};
for y=1:length(indices)
    for indices{y}=1:length(A)
            string(z,y)=A(indices(y));
...

But at line 3 we are poofing a new variable at each iteration of the for loop.  The first time we are poofing a, the second time b, etc...


Is there a way to do this without poofing variables ??
------------------------------------------------------------------------------------------------------
Also, the using eval command doesn't necessarily mean we're poofing variables into existence.... Let's say we had the variables AAAA,AAAB,AAAC,......DDDC,DDDD ALREADY defined and set to equal numerical values.   Now I want to put only ones with two of the same letter into a cell array.

So I should get a cell array like: 
cell= {AABB,AACC,AADD,BBAA,BBCC....DDCC}

WITH their numerical values attached to those cell array entries.  Defining the cell the way I did just now would take a long time especially if we add E and F.  But one thing I can do is come up with an algorithm that generates the names of the variables I want, and then defines those variables to equal the corresponding variables that previously existed, using the eval command and "poofing" variables (already they already existed before).

Would there be a way out of this one ?? Does it involve the symbolic toolkit ??