Discussion:
Load .mat into base workspace from function workspace
(too old to reply)
Jason
2006-10-09 21:12:06 UTC
Permalink
Hello,

I am trying to use the load function to load a .mat containing a
structure from function workspace into the base workspace. I have
tried evalin but this is not defined for structures. I have also
tried assignin, but this does not inherit the exact naming of the
structure when it is copied into the base workspace (you must supply
a name in the target workspace, so you get a double named structure).


Anyone overcome this?

Thanks,

Jason
Markus Nenniger
2006-10-10 08:43:39 UTC
Permalink
Post by Jason
Hello,
I am trying to use the load function to load a .mat containing a
structure from function workspace into the base workspace. I have
tried evalin but this is not defined for structures. I have also
tried assignin, but this does not inherit the exact naming of the
structure when it is copied into the base workspace (you must
supply
a name in the target workspace, so you get a double named
structure).
Anyone overcome this?
Thanks,
Jason
load it, make it global, copy it inside base, clear global.
everything should be done 'by reference', so you don't waste any
memory.

Markus
Michael
2010-11-02 17:28:04 UTC
Permalink
Post by Jason
Hello,
I am trying to use the load function to load a .mat containing a
structure from function workspace into the base workspace. I have
tried evalin but this is not defined for structures. I have also
tried assignin, but this does not inherit the exact naming of the
structure when it is copied into the base workspace (you must supply
a name in the target workspace, so you get a double named structure).
Anyone overcome this?
Thanks,
Jason
Save the workspace with "save" (if you don't choose a name to save the file under it will save it under matlab.mat in the current directory). Then use evalin('base', 'load') to load the workspace into the base workspace. The load command follows the same default as the save command if there is now file specified.
Jan Simon
2010-11-02 17:58:04 UTC
Permalink
Dear Jason,
Post by Jason
I am trying to use the load function to load a .mat containing a
structure from function workspace into the base workspace.
I have tried evalin but this is not defined for structures.
Please show us, what you have tried. Of course EVALIN works fur structures. So I assume, that your EVALIN call is wrong.
Post by Jason
I have also tried assignin, but this does not inherit the exact naming of the
structure when it is copied into the base workspace (you must supply
a name in the target workspace, so you get a double named structure).
What is a double named structure??
From where do you call LOAD? From the function or from the base workspace? Can you assign the variable directly or is it useful to write it to the MAT file at first?

Writing variables in the base workspace remotely by ASSIGNIN or EVALIN is very susceptible for errors and problems - as your post prooves another time. A regular transport of variables as input and output of functions avoids this level of confusion. Especially of you -or even worse: somebody else- has to debug the program in the future, the ASSIGNIN and EVALIN tricks will be the programmers hell.

Kind regards, Jan

Loading...