save variables from GUI to workspace (variables not accesible )

hello I created a GUI with GUIDE and values are entered by the GUI Variables are then saved seperately in a text file all perfect. BUT I cannot acces to the variables in the WORKSPACE.
I would like to make my variables visible and so that i can acces to them for further projects.
Can someone HELP please thank u a lot.

Answers (1)

Which ever variables you would like to be in the workspace simply save them off to the base workspace by doing
myVar = 5
assignin('base','myVar',myVar)
in this case assignin takes three arguments. First, the workspace to save the variable. Second, the name of the variable. Lastly, the value of the variable.

3 Comments

Hello. I have a similar problem. On pushing a button, I need an action to be executed and also a variable to be stored. The exectuted action is uigetfile to obtain the path to a file. The variable is the path to the file so my program accesses that file later. I suppose it is a string(?). I tried getting that variable like I would in a regular function:
function [file_path]=pushbutton1_Callback(hObject, eventdata, handles)
but I suppose that's not the way to do it. In your answer you said I should specify the value of a variable when using assignin, but how do I specify this if it's not numerical? Thank you
uicontrol callbacks cannot return a value. See though
Note:
assignin('base', 'myvar', file_path)
would be valid when file_path is a string.
the best way is to use " assignin"
assignin('base', 'x', x);

Sign in to comment.

Categories

Find more on Scope Variables and Generate Names in Help Center and File Exchange

Asked:

on 7 Feb 2015

Commented:

on 17 Jul 2020

Community Treasure Hunt

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

Start Hunting!