Hello, I will try to make myself as clear as I can. I am having two figs and when I press a button(the button next) in the first one, I want to close(I use the command close; the figure no1 and leave open only the figure np2. The problem is that I want to pass a variable(or more) from the first figure to the second and by using setappdata/getappdata the code does not work. Is there any way to do that, because otherwise I will have 7 open figures, in order to pass variables to the next one.
Yes, you can use setappdata/getappdata.
Does not work is a rather weak describtion of the problem, without knowing what the problem is or seeing any code it is harder to provide an answer that does help you.
Minimalistic example of 2 figures passing a value from one to another and closing figure one (does only work if you push the button in figure 1 first):
handles.fig1=figure; handles.fig2=figure; handles.pb1=uicontrol('parent',handles.fig1,'style','pushbutton','callback',@fig1_callback); handles.pb2=uicontrol('parent',handles.fig2,'style','pushbutton','callback',@fig2_callback); setappdata(handles.pb1,'h',handles) setappdata(handles.pb2,'h',handles)
function fig1_callback(hObj,~) handles=getappdata(hObj,'h'); myvalue=randi(5); setappdata(handles.pb2,'value',myvalue) close(handles.fig1) end
function fig2_callback(hObj,~) myvalue=getappdata(hObj,'value'); disp(myvalue) end
Thanks for the answers, but my code doesnt seem to work when I put what Walter said. I made a simplier code so you can help me with what to add so my code to work properly. So, I have two figs, zb1 and zb2 and will attach both m and fig files, cause I think with my small experience I cant make myself clear with small part of the code.
So, when I put breakpoints, the variable signal is an empty matrix in zb2. Why is that and what can I change?