필터 지우기
필터 지우기

In one UItable CellselectionCallBack fucntion can i call another UItable CellselectionCallBack function?

조회 수: 1 (최근 30일)
I have two Uitables .i am checking which cell the user chooses by calling its CellselectionCallBack function and at the same time i want to check which cell the user chooses in the second table also.Is this possible?
Kindly help with this.Any help is appreciated?

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 4월 24일
You cannot "call" the callback function. Callback functions are event-driven, and therefore only triggered when the corresponding event occurs. What you want to do it to create a "central" variable that both callback function can access. So whenever a callback is executed, it will write the required value to the "central" variable, which other callback can also access anytime. The given image describe the scheme. Fortunately, every graphic object has a property called UserData which is there for the user to save data inside the graphics object handle. MATLAB itself never uses UserData property. In your case, you can use UserData property of figure object to save the values of selected cells. A general sketch to do this is
function CBuitable1(HObj, event)
selectedCellTable1 = event.Indices;
% access the selected cell of uitable2 from "central" varable as follow
try
selectedCellTable2 = HObj.Parent.UserData.table2;
catch
selectedCellTable2 = [];
end
% also remember to save the indices of Table1 to the "central" variable
HObj.Parent.UserData.table1 = selectedCellTable1;
% do other things you want
end
Similarly, for the second uitable, do it like this
function CBuitable2(HObj, event)
selectedCellTable2 = event.Indices;
% access the selected cell of uitable2 from "central" varable as follow
try
selectedCellTable1 = HObj.Parent.UserData.table1;
catch
selectedCellTable1 = [];
end
% also remember to save the indices of Table1 to the "central" variable
HObj.Parent.UserData.table2 = selectedCellTable2;
% do other things you want
end
Using this mechanism, you can share variables among several callbacks.
%

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by