Borrar filtros
Borrar filtros

How to create a big mat.file including many variables generated in a GUI

1 visualización (últimos 30 días)
Hi Guys,
i execute a function within a GUI and the calculated variables are not in the workspace but only available within the GUI. How can i save those variables to a mat.file. I know i could write all of them into the workspace and apply the command
save('path\myfile.mat');
BUt isnt that unnecessary and ineffective to write it into workspace first? How can i save all generated variables in my GUI as a mat.file without transferring them to workspace first? is there a possibility for that?
I am very glad for help!
Best regards, John;)

Respuesta aceptada

Stephen23
Stephen23 el 21 de Sept. de 2015
Editada: Stephen23 el 21 de Sept. de 2015
Of course you can save those variable directly from the GUI workspace. And yes it is inefficient to transfer them to the base workspace, if they are not required there. Your code
save('path\myfile.mat');
will work just as well inside the GUI workspace as it does in the base workspace.
With a few minor differences basically every workspace (base or function) lets you do the same things: create variables, save them, call other functions, etc, etc. The difference are noted in the documentation (e.g. nargin), but functions like save can be called from any workspace.
You should read about the different workspaces:
and how to share data between them
Note that the most efficient way to share data is to pass them as variables, and the least efficient way is to use assignin or evalin (although beginners seem to love using these two functions they should be avoided).
  5 comentarios
Stephen23
Stephen23 el 21 de Sept. de 2015
Editada: Stephen23 el 21 de Sept. de 2015
This is exactly what uiputfile does: lets the user designate a folder and a filename. You already use this in your code, so just change the filter spec to '*.mat' and they will be able to select the name as well:
[myfile,mypath] = uiputfile('*.mat');
Note that path is a very bad name for a variable, because this is the name of an important inbuilt function path, which will not work when you define a variable with the same name. You can use which to check if variable names are already defined.
John
John el 21 de Sept. de 2015
thank you very much!!! i got it now! :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Workspace Variables and MAT-Files en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by