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 CenterFile Exchange에서 Resampling Techniques에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by