How can i save GUI data to a workspace

5 visualizzazioni (ultimi 30 giorni)
Nik
Nik il 29 Nov 2014
Modificato: Geoff Hayes il 30 Nov 2014
Hi guys, i've got a problem over here. I've create a GUI with one edit text and one push button .
My objective is that if i type a number in the edit text box and press the push button, I wanna store the number that I've just type in into a variable name: b in the MATLAB workspace. I want the variable b can be store so that i can call it in the command window.
I've done several research that requires me to use the global variable. Thus i need to type global b first before i can execute my command from the GUI itself. I wanna it to be automatically without me declare the global variable first.Anyone can help me???

Risposte (1)

Image Analyst
Image Analyst il 29 Nov 2014
If you don't want to set a global variable, you can just get the value whenever you need it using the known name of the edit field:
editString = get(handles.edit1, 'String');
b = str2double(editString);
That will work in any callback function or any other custom function that you've passed the handles structure to.
  1 Commento
Geoff Hayes
Geoff Hayes il 30 Nov 2014
Modificato: Geoff Hayes il 30 Nov 2014
To get to handles outside of the GUI, from the Command Window for example, you may need to set the HandleVisibility property of the GUI figure to on. Then if you know the Tag of the figure, you would do
hFig = findobj('Tag', 'myFigTag');
if ~isempty(hFig)
handles = guidata(hFig);
% etc
end
where myFigTag is the name/tag of your GUI figure.

Accedi per commentare.

Categorie

Scopri di più su Creating, Deleting, and Querying Graphics Objects in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by