Borrar filtros
Borrar filtros

How to pass values between callback functions in GUI?

1 visualización (últimos 30 días)
Ali Y.
Ali Y. el 5 de Ag. de 2015
Editada: Ali Y. el 6 de Ag. de 2015
I know my question have been repeated many time in this platform, but since I have tried some suggested answers and get nothing to solve my problem, I am writing this question. I have made a GUI that includes different components. My general problem is how to pass values of different callback functions from one to other. For example in my GUI, I have two push-button callbacks, one for plotting and the other one for clearing the figure, that is out of GUI window/figure.
function pbplot_Callback(hObject, eventdata,handles) % plotting function (push-button)
figure (1)
plot(x,y, 'color', [a b c], 'linestyle', d)
hplot = findobj('Type','figure');
hold on % this is for adding new graphs
handles.hplot = hplot
guidata(hObject,handles)
function pbclear_Callback(hObject, eventdata,handles) % clearing function (push-button)
hplot = handles.hplot;
clf (hplot)
guidata(hObject,handles)
The error I get when I push the plot push-button is "Attempt to reference field of non-structure array." referring to "guidata(hObject.handles)". Getting information from handels, within plot callback function, shows "hplot: {2x1 double]". Could someone please help me to find the problem.
PS: x,y,a,b,c, and d are intorduced to the plot callback function.
  2 comentarios
Ali Y.
Ali Y. el 6 de Ag. de 2015
Editada: Ali Y. el 6 de Ag. de 2015
Thank you Stephen. I have to say that, I already tried Matlab's helps, but I think there is a glitch in my neuron system :) causing not to understand the help comprehensively. You can say do not use the Matlab if so, but I have to use it. Although, I solved my problem just by clf(figure(1)), but still need any help to understand the passing issue.
About my question, I think the problem return to figure properties, because in other callbacks I am able to pass data, if not all the time. In this case, I tried the following, but still can not get hplot outside of plot push button.
function pbplot_Callback(hObject, eventdata,handles) % plotting callback
hplot = figure (1)
plot(x,y, 'color', [a b c], 'linestyle', d)
hold on
guidata(hfig,struct('val', 0)) % this gives me number 1, the value I need to pass to the other function.
guidata(hObject,hfig) % This doesn't pass the hplot value (1)???
function pbclear_Callback(hObject, eventdata,handles) % clearing callback
guidata(hplot) % not working
guidata(hObject,hplot) % not working
clf (hplot)

Iniciar sesión para comentar.

Respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 5 de Ag. de 2015
Use guidata
  1 comentario
Ali Y.
Ali Y. el 6 de Ag. de 2015
Hi Azzi; I'm trying guidata, but in this case it doesn't work. I think I don't get right properties of the figure.

Iniciar sesión para comentar.

Categorías

Más información sobre Interactive Control and Callbacks 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