<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167942</link>
    <title>MATLAB Central Newsreader - eval begone!</title>
    <description>Feed for thread: eval begone!</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2008 by The MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>The MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Mon, 21 Apr 2008 04:12:02 -0400</pubDate>
      <title>eval begone!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167942#427886</link>
      <author>jay vaughan</author>
      <description>Hi,&lt;br&gt;
&lt;br&gt;
I've seen many posts on the Matlab newsgroup stating that&lt;br&gt;
eval is evil and should be avoided. Upon attempting to&lt;br&gt;
exorcise my code, I couldn't get rid of one of them...&lt;br&gt;
&lt;br&gt;
Essentially I have a variable 'var' which I want to save&lt;br&gt;
within a .mat file but with a name other than 'var'. The&lt;br&gt;
user supplies the name. Here's how I do it now.&lt;br&gt;
&lt;br&gt;
var = [1 2 3];&lt;br&gt;
answer = inputdlg('choose a name');&lt;br&gt;
var_name_from_user = answer{1};&lt;br&gt;
eval([var_name_from_user '=var;']);&lt;br&gt;
save('saved_file.mat',var_name_from_user);&lt;br&gt;
&lt;br&gt;
Any ideas how to do this without eval? It's probably easy&lt;br&gt;
but I just can't see it. &lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
J&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 21 Apr 2008 04:16:43 -0400</pubDate>
      <title>Re: eval begone!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167942#427888</link>
      <author>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)</author>
      <description>In article &amp;lt;fuh46i$pav$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
jay vaughan &amp;lt;jvaughan5.nospam@gmail.com&amp;gt; wrote:&lt;br&gt;
&lt;br&gt;
&amp;gt;I've seen many posts on the Matlab newsgroup stating that&lt;br&gt;
&amp;gt;eval is evil and should be avoided. Upon attempting to&lt;br&gt;
&amp;gt;exorcise my code, I couldn't get rid of one of them...&lt;br&gt;
&lt;br&gt;
&amp;gt;Essentially I have a variable 'var' which I want to save&lt;br&gt;
&amp;gt;within a .mat file but with a name other than 'var'. The&lt;br&gt;
&amp;gt;user supplies the name. Here's how I do it now.&lt;br&gt;
&lt;br&gt;
&amp;gt;var = [1 2 3];&lt;br&gt;
&amp;gt;answer = inputdlg('choose a name');&lt;br&gt;
&amp;gt;var_name_from_user = answer{1};&lt;br&gt;
&amp;gt;eval([var_name_from_user '=var;']);&lt;br&gt;
&amp;gt;save('saved_file.mat',var_name_from_user);&lt;br&gt;
&lt;br&gt;
&amp;gt;Any ideas how to do this without eval? It's probably easy&lt;br&gt;
&amp;gt;but I just can't see it. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
outstruct.(var_name_from_user) = var;&lt;br&gt;
save('saved_file.mat', 'outstruct', '-struct');&lt;br&gt;
-- &lt;br&gt;
&amp;nbsp;&amp;nbsp;"Why does he stagger his mind with the mathematics of the sky?&lt;br&gt;
&amp;nbsp;&amp;nbsp;Once the question mark has arisen in the human brain the answer must&lt;br&gt;
&amp;nbsp;&amp;nbsp;be found, if it takes a hundred years. A thousand years."&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;-- Walter Reisch&lt;br&gt;
</description>
    </item>
    <item>
      <pubDate>Mon, 21 Apr 2008 04:45:03 -0400</pubDate>
      <title>Re: eval begone!</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/167942#427891</link>
      <author>jay vaughan</author>
      <description>&lt;br&gt;
Walter,&lt;br&gt;
&lt;br&gt;
Very clever...I like it. &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thanks,&lt;br&gt;
&lt;br&gt;
J&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
P.S. Minor detail...I had to put '-struct' before struct&lt;br&gt;
name 'outstruct' as shown below...&lt;br&gt;
&lt;br&gt;
save('saved_file.mat', '-struct', 'outstruct');&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in&lt;br&gt;
message &amp;lt;fuh4fb$743$1@canopus.cc.umanitoba.ca&amp;gt;...&lt;br&gt;
&amp;gt; In article &amp;lt;fuh46i$pav$1@fred.mathworks.com&amp;gt;,&lt;br&gt;
&amp;gt; jay vaughan &amp;lt;jvaughan5.nospam@gmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;I've seen many posts on the Matlab newsgroup stating that&lt;br&gt;
&amp;gt; &amp;gt;eval is evil and should be avoided. Upon attempting to&lt;br&gt;
&amp;gt; &amp;gt;exorcise my code, I couldn't get rid of one of them...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;Essentially I have a variable 'var' which I want to save&lt;br&gt;
&amp;gt; &amp;gt;within a .mat file but with a name other than 'var'. The&lt;br&gt;
&amp;gt; &amp;gt;user supplies the name. Here's how I do it now.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;var = [1 2 3];&lt;br&gt;
&amp;gt; &amp;gt;answer = inputdlg('choose a name');&lt;br&gt;
&amp;gt; &amp;gt;var_name_from_user = answer{1};&lt;br&gt;
&amp;gt; &amp;gt;eval([var_name_from_user '=var;']);&lt;br&gt;
&amp;gt; &amp;gt;save('saved_file.mat',var_name_from_user);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &amp;gt;Any ideas how to do this without eval? It's probably easy&lt;br&gt;
&amp;gt; &amp;gt;but I just can't see it. &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; outstruct.(var_name_from_user) = var;&lt;br&gt;
&amp;gt; save('saved_file.mat', 'outstruct', '-struct');&lt;br&gt;
&amp;gt; -- &lt;br&gt;
&amp;gt;   "Why does he stagger his mind with the mathematics of&lt;br&gt;
the sky?&lt;br&gt;
&amp;gt;   Once the question mark has arisen in the human brain the&lt;br&gt;
answer must&lt;br&gt;
&amp;gt;   be found, if it takes a hundred years. A thousand years."&lt;br&gt;
&amp;gt;                                               -- Walter Reisch&lt;br&gt;
&lt;br&gt;
</description>
    </item>
  </channel>
</rss>
