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

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 个)

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 个评论

ali's answer moved here
thank you so much i will try it and tell you the ressult

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by