Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: genvarname doesn't work
Date: Fri, 10 Jul 2009 17:51:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 19
Message-ID: <h37v27$6n4$1@fred.mathworks.com>
References: <h37t8i$6kh$1@fred.mathworks.com> <h37u9p$fho$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 1247248263 6884 172.30.248.35 (10 Jul 2009 17:51:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 10 Jul 2009 17:51:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1646679
Xref: news.mathworks.com comp.soft-sys.matlab:554536


Thank Wayne,
I did clear('all') then reran the code and it worked, so it must have been some predefined variable in my workspace messing it up.

Anyway, I can't seem to get this to work.

If I have an array of strings like:

xhat=['a' 'b' 'c' 'd']; 

and I want to define 4 variables whose names are the elements of xhat.. let's say for example, I wanted a=1,b=2,c=3,d=4 ... it would be nice if I could do:

for i=1:4
 genvarname(xhat(i))=i
end

But this does not work as I discovered in the documentation for genvarname: 
"genvarname returns a string that can be used as a variable name. It does not create a variable in the MATLAB workspace. You cannot, therefore, assign a value to the output of genvarname."

is there a way ??