How to create the datas of third uitable by selecting a data in 1st uitable and a data in 2nd uitable?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
sachin narain
il 25 Apr 2018
Commentato: Ameer Hamza
il 27 Apr 2018
I have three uitables(Tracks, Profil ,Markings)formed in Matlab Guide .I have column called Location in the 1st UItable.Location has 3 datas:'City','Country' and' Highway'.In another Uitable i have a column called number of ways which has data like :1,2,3,4 .If the user selects Location as Highway and number of ways 1 the third uitable should contain a column 'Direction' which has some value.If the user chooses Location as 'City' and number of ways as 2 the 'Direction'column in the third uitable should have some other value .Similary there can be different cases.
Till now i am able to apply a cellSelection fucntion to the 1st table and then when the user selects a cell inside 'Location', i find the cell indices where the column 'Location' is,but now how do i check what the user selects in the 2nd Uitable(since these are two seperate tables). After he selects the cell in the 2nd Uitable ,how do i create the 3rd table marking with the column direction with the required values
I will attach pictures of the Uitables along with this. Kindlt help me with this.Urgent need of a solution.
Thank you in advance
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189225/image.png)
1 Commento
Walter Roberson
il 26 Apr 2018
Duplicates earlier https://www.mathworks.com/matlabcentral/answers/397289-how-can-i-create-a-third-uitable-with-the-datas-according-to-the-data-in-the-1st-and-2nd-uitable-in which also has an answer.
Risposta accettata
Ameer Hamza
il 25 Apr 2018
There are several ways to communicate information between different UI elements. Here I am describing one of them. The key point is to understand the Parent and Children relation between MATLAB graphics objects. In your example, three tables are the Children of the figure window in which they are located. The easiest way for communication among several Children object is through parent object (in your case the figure window). Fortunately, in MATLAB, each graphics Object has a property called UserData, which MATLAB never uses and it is there to allow a user to store its own data. Understanding this. Here is a basic sketch what you can do,
table1 = uitable(...); % table1 is handle to first table
table2 = uitable(...); % file ... according to your table contents
table3 = uitable(...);
f = table1.Parent; % table2.Parent; table3.Parent; are all valid, since all have same parent
f.UserData.tab1 = table1; % populate the 'UserData' field with table handles.
f.UserData.tab2 = table2; % now all tables can access other like
f.UserData.tab3 = table3; % this: table1.Parent.UserData.table3.Data . Here table 1 is accessing table 3 Data field.
Now the next issue is how can we know, which cell of each table is selected. Here we will use CellSelectionCallback. The callback function will also set some fields in UserData property of figure f so that other tables can also access it. It can be done like this
f.UserData.tab1CurrentCell = [];
f.UserData.tab2CurrentCell = [];
f.UserData.tab3CurrentCell = [];
and then define callbacks like this
function table1CellSelectionCallBack(HObj, event)
% This function will be called when a cell on table 1 is selected. Therefore first we
% should save the value in 'UserData' so that other table can find updated value when they check.
HObj.Parent.UserData.tab1CurrentCell = event.Indices;
% to know current selection of table 2 and 3 do
currentSelectTable2 = HObj.Parent.UserData.tab2CurrentCell;
currentSelectTable3 = HObj.Parent.UserData.tab3CurrentCell;
% do whatever computation you want
% to change the value of some other table do
HObj.Parent.UserData.tab3.Data = []; % write value to table 3.
end
Similar callbacks can be written for table 2 and table 3 CellSelectionCallback. For more details on this topic, refer to my this answer.
13 Commenti
Ameer Hamza
il 27 Apr 2018
@Sachin What is display in the command window. Does it change when you select different cells in table 1 and 2.
Also, remember to add the line
guidata(hObject, handles);
to the second callback. In your last comment, it is not there.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Whos in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!