how can solve this probleme ??? Undefined function or variable

1 回表示 (過去 30 日間)
ali hadjer
ali hadjer 2015 年 11 月 1 日
編集済み: Walter Roberson 2015 年 11 月 2 日
hello
how can i use the information defined in pushbutton1_Callback in the other pushbutton2_Callback without have this msg error
??? Undefined function or variable "net".
Error in ==> untitled>pushbutton2_Callback at 260
plot(net(2,:),net(3,:),'r.','MarkerSize',15);
Error in ==> gui_mainfcn at 98
feval(varargin{:});
Error in ==> untitled at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)untitled('pushbutton2_Callback',hObject,eventdata,guidata(hObject))

回答 (1 件)

Geoff Hayes
Geoff Hayes 2015 年 11 月 1 日
編集済み: Geoff Hayes 2015 年 11 月 1 日
Ali - you can easily make data available in other callbacks by using the handles structure (which is passed as the third parameter to each of your callbacks, assuming that you are using GUIDE). What you need to do is save the net data to handles in the callback for pushbutton1, and then access it from handles in the callback for pushbutton2. For example,
function pushbutton1_Callback(hObject, eventdata, handles)
% do something to get net and update the handles structure
handles.net = net;
guidata(hObject,handles); % now save the updated handles structure
Note the use of guidata which is important in saving the updated handles structure. Now, in your second callback access net as
function pushbutton2_Callback(hObject, eventdata, handles)
if isfield(handles,'net')
plot(handles.net(2,:),handles.net(3,:),'r.','MarkerSize',15);
end
And that is it. The isfield is used above to make sure that the net exists in handles before we try to access it.
  2 件のコメント
Geoff Hayes
Geoff Hayes 2015 年 11 月 1 日
ali's answer moved here
thank you so much i will try it and tell you the ressult
ali hadjer
ali hadjer 2015 年 11 月 1 日
thank you its work thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResampling Techniques についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by