MATLAB: Matlab Guis setapp/getapp as global variables

globalguiMATLABvariables

Hi, I'm trying to use setapp and getapp to pass variable between GUIs. The variables will passed from 1 GUI and then be used to display those variables on another GUI. I got them them to work, however, when I close the GUI and run it, the numbers are still displayed on the screen on the GUI, and I thought they were supposed to be reset since I'm not using global variables.
Here's what im doing.
Gui1
variable1= get(handles.number,'String') %this reads a value from a string that is already displayed on handles.number on GUI1 and assigns it to variable 1
setappdata(0, 'variable1', variable1)
Gui2 (Receives variable1 from GUI2 and displays it in a static text num_display)
variable1= getappdata(0, 'variable1')
set(handles.num_display,'String',variable1)
I want to reset the variables whenever the GUI stops running.

Best Answer

You are setting the application data to the root, i.e. 0. This will persist throughout the entire MATLAB session unless you call rmappdata()
Instead set it to the handles of the figure.
setappdata(handles.figure1,'blah',blah)
Where figure1 is the tag of the main figure. Now when the figure closes, this info is gone.
Related Question