Path: news.mathworks.com!not-for-mail
From: "jay vaughan" <jvaughan5.nospam@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: eval begone!
Date: Mon, 21 Apr 2008 04:12:02 +0000 (UTC)
Organization: harvard
Lines: 21
Message-ID: <fuh46i$pav$1@fred.mathworks.com>
Reply-To: "jay vaughan" <jvaughan5.nospam@gmail.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1208751122 25951 172.30.248.37 (21 Apr 2008 04:12:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 21 Apr 2008 04:12:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1215048
Xref: news.mathworks.com comp.soft-sys.matlab:464228


Hi,

I've seen many posts on the Matlab newsgroup stating that
eval is evil and should be avoided. Upon attempting to
exorcise my code, I couldn't get rid of one of them...

Essentially I have a variable 'var' which I want to save
within a .mat file but with a name other than 'var'. The
user supplies the name. Here's how I do it now.

var = [1 2 3];
answer = inputdlg('choose a name');
var_name_from_user = answer{1};
eval([var_name_from_user '=var;']);
save('saved_file.mat',var_name_from_user);

Any ideas how to do this without eval? It's probably easy
but I just can't see it. 

Thanks,
J