From: Fangjun Jiang on
"d c" <myspamcatcher07(a)gmail.com> wrote in message <i41cft$1k5$1(a)fred.mathworks.com>...
> Is there a quick way to dumping a collection of variables to a structure, using the variable names as the structure fields? The "load" function basically does this somehow? Sorry if this has been answered, I'm just finding a solution quickly.
>
> i.e.
>
> clear
> a = 'adsf'
> b = rand(10);
>
> x = var2struct(a,b)
>
> x.a
> x.b
>
> Also, what about the reverse? Dumping a.* variables to the current scope?
> clear
> x.a='asdf'
> x.b=rand(10);
> dumpstruct(x)
> a
> b

help cell2struct
help struct2cell
help fieldnames


x=cell2struct({a;b},{'a';'b'},1)
x =

a: 'adsf'
b: [10x10 double]
From: Matt J on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <i41fi3$j4e$1(a)fred.mathworks.com>...
> You could use load, but you mention this and seem unhappy with this option. If you want to write your own functions, you could do:
>
>
> function [] = struct2var(M)
> F = fieldnames(M)
> for ii = 1:length(F)
> assignin('caller',F{ii},M.(F{ii}));
> end
>
================

You could, but it is inadvisable, for reasons discussed here

http://www.mathworks.com/matlabcentral/newsreader/view_thread/244639#628695

It is why I wrote this tool as a compromise

http://www.mathworks.com/matlabcentral/fileexchange/26216-structure-fields-to-variables
From: Matt Fig on
"Matt J " <mattjacREMOVE(a)THISieee.spam> wrote in message
> You could, but it is inadvisable, for reasons discussed here
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/244639#628695
>
> It is why I wrote this tool as a compromise
>
> http://www.mathworks.com/matlabcentral/fileexchange/26216-structure-fields-to-variables


Ah yes, I should have included the usual warnings about the potential problems of poofing. Thanks Matt J.