フィルターのクリア

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 件のコメント
Stephen23
Stephen23 2015 年 8 月 5 日
編集済み: Stephen23 2015 年 8 月 5 日
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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by