title: How can I move variables into and out of a structure akin to LOAD and SAVE in MATLAB?
body: <p>Is there a quick way (i.e. one line) to dump a collection of variables "in" a structure, using the variable names as the structure fields? The "load" function basically does this but saving and loading to a temporary file seems ugly.</p>
  
  <p>For example:</p>
  
  <pre><code>clear
  a = 'adsf'
  b = rand(10);
  
  x = var2struct(a,b)
  
  x.a
  x.b
  </code></pre>
  
  <p>or better yet:</p>
  
  <pre><code>x = var2struct(['a';'b'])
  </code></pre>
  
  <p>Also, what about the reverse (i.e. dumping the field values to the current scope as variables named after the fields)?:</p>
  
  <pre><code>clear
  x.a='asdf'
  x.b=rand(10);
  dumpstruct(x)
  a
  b 
  </code></pre>
  
  <p>Also, here's a related <a href="http://www.mathworks.cn/matlabcentral/newsreader/view_thread/289189" rel="nofollow noreferrer">newsgroup thread</a>.</p>