[Guide] Pass a variable between two functions using handles.

조회 수: 32 (최근 30일)
Waqar Ali Memon
Waqar Ali Memon 2019년 8월 14일
댓글: Waqar Ali Memon 2019년 8월 14일
Hello Everyone,
I am incurring error in passing a variable between two functions.
In 1st Function (PushButton):
Where variable (myTable_Selection) is present. i have done following:
myTable_Final.handles = myTable_Selection
guidata(hObject, handles)
But I am unable to recall this variable in another function (PushButton).
myTable_Final = myTable_Final.handles; % Line 515
Error is:
Undefined function or variable 'myTable_Final'.
Error in PFT_GUI>exp_selected_Callback (line 515)
myTable_Final = myTable_Final.handles;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in PFT_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)PFT_GUI('exp_selected_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Note: I am able to pass all other variables except this myTable_Selection.
Any help would be appreciated :-)
Regard,s
Waqar Ali Memon

채택된 답변

Steven Lord
Steven Lord 2019년 8월 14일
Each callback function has its own workspace, separate from the rest. Creating a variable in one doesn't automatically create it in others. To share data between those workspaces use one of the techniques illustrated on this documentation page.
The technique you attempted:
myTable_Final.handles = myTable_Selection
guidata(hObject, handles)
looks like the "Store Data Using the guidata Function" approach, but your first line did not affect the handles struct in the workspace of that callback. Something like this should work and should allow you to access the selection in the other callback function's workspace using handles.Selection:
handles.Selection = myTable_Selection;
guidata(hObject, handles)

추가 답변 (1개)

Waqar Ali Memon
Waqar Ali Memon 2019년 8월 14일

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by