GUIDE: set handle with function

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
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
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…
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
Lorenzo am 8 Jul. 2013
Thank you Image Analyst. This is exactly what I'm doing at the moment. What I would like to do, instead, is a little bit different: I would like to have a generic function that does that for every each one of my tables without the need of setting hanldes.uitable1/2/3…
Jan
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
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
Lorenzo am 9 Jul. 2013
Yes, exactly... That is my problem. What is the purpose of a function? To generalize the problem. Let's say you have a set of data: you use a function so that if your set of data changes you just run the function again without changing anything and this gives you your results. Now: I have 3 tables and I want to edit them with the same function. Let's say I add another 30 tables. Any way to use the same function without having to update it but just using the exact one I was using for the 3 tables I had before? So far it is not clear to me if this can be achieved or not...
Thank you all for your availability!
Image Analyst
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
Lorenzo am 10 Jul. 2013
Ok, so I guess I cannot do what I was asking to...
Thank you anyway for your help!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Identification finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 7 Jul. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by