GUIDE: set handle with function
Ältere Kommentare anzeigen
Dear all;
I'm building a GUI with GUIDE and I have few tables. Now, for every each one of those tables I want to set the data according to different conditions (related to a different popup assigned to each table) and if the conditions are the same for two different tables then the data I'm setting are the same for the two tables. Now, to do so, it would be nice if I could use the same function for all of those table. What I have so far is this (for table 1 taken as an example):
function popupmenu1_Callback(hObject, eventdata, handles)
val1 = get(hObject,'Value');
table1(val1,handles)
And inside the function called table1 I have:
function [a]=table1(val1,handles)
if val1 == 1
set(handles.uitable1,'Data',list_a,'Enable','off')
elseif val1 == 2
set(handles.uitable1,'Data',list_b,'Enable','on')
elseif val1 == 3
[...]
Now, for the other tables I have the same thing but instead of calling the function table1 I'm calling table2, table3 and so forth which in turn will set handles.uitable2, handles.uitable3 and so on...
Now, is there any way to generalize this and have only one function instead of table1, table2, table3??
Thank you all!
Antworten (1)
Image Analyst
am 7 Jul. 2013
0 Stimmen
Sure, just have one function called "SetAllTables" and call that in every function of every control (popup) that needs to do this. In the SetAllTables you can just do all three tables. No need to have one function per table if you don't want to.
8 Kommentare
Image Analyst
am 7 Jul. 2013
Lorenzo's "Answer" moved here as a "Comment":
Thank you Image Analyst for your answer.That is actually what I would like to achieve but I don't know how… My problem is that every function needs a different handles.uitableX and I don't know how to handle this handle in one function only…
Myabe I didn't explain clearly my problem, sorry…
Image Analyst
am 7 Jul. 2013
The handles structure contains everything - all you need because it contains handles for every single control on the GUI. All you have to do is to use them by name. Actually I never use hObjects at all.
function status = SetAllTables(handles)
% Get values of all the popups.
val1 = get(handles.popup1, 'value');
val2 = get(handles.popup2, 'value');
val3 = get(handles.popup3, 'value');
if val1 == 1
set(handles.uitable1,'Data',list_a,'Enable','off')
elseif val1 == 2
set(handles.uitable1,'Data',list_b,'Enable','on')
elseif val1 == 3
[...]
if val2 == 1
set(handles.uitable2,'Data',list_a,'Enable','off')
elseif val2 == 2
set(handles.uitable2,'Data',list_b,'Enable','on')
elseif val2 == 3
[...]
% and same for table 3
Lorenzo
am 8 Jul. 2013
Jan
am 8 Jul. 2013
Do you want to store the handles in a vector instead?
% In the CreateFcn or anywhere else:
handles.uitable = [handles.uitable1, handles.uitable2, handles.uitable3];
Image Analyst
am 8 Jul. 2013
But you have to do it differently for each table. Otherwise every table will have the same thing in it.
Lorenzo
am 9 Jul. 2013
Image Analyst
am 9 Jul. 2013
If you want, you can make a function that takes a handle and a popup selection number and send those to a function. But you still have to put a call to that function inside each callback of each popup.
Lorenzo
am 10 Jul. 2013
Kategorien
Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!