필터 지우기
필터 지우기

How to pass values between callback functions in GUI?

조회 수: 1 (최근 30일)
Ali Y.
Ali Y. 2015년 8월 5일
편집: Ali Y. 2015년 8월 6일
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
Ali Y.
Ali Y. 2015년 8월 6일
편집: Ali Y. 2015년 8월 6일
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)

댓글을 달려면 로그인하십시오.

답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 5일
Use guidata
  댓글 수: 1
Ali Y.
Ali Y. 2015년 8월 6일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by