Duplicated elements in a GUI

1 view (last 30 days)
Lorenzo
Lorenzo on 8 Nov 2013
Answered: Lorenzo on 10 Nov 2013
Dear all, I have a gui with 20 different tables. They all perform the same calculation with the data entered in each one of them by the user.
At the moment I have this in my function:
function uitable1_CellEditCallback(hObject, ~, handles)
calculation
function uitable2_CellEditCallback(hObject, ~, handles)
calculation
function uitable3_CellEditCallback(hObject, ~, handles)
calculation
Any chance to do that in a cleaner way without having to repeat the same block of code over and over?
Thanks!

Answers (4)

Sean de Wolski
Sean de Wolski on 8 Nov 2013
Absolutely.
You can go into GUIDE and use the property inspector to change the callback manually. Copy the callback from the first UITABLE's GUIDE Inspector window and paste it into the others. Now you'll have one callback for all of them and have them all point at it.
Inside of the Callback, the first input hObject is the handle to the specific uitable that is calling the callback. Thus if you need some logic based on the calling uitable, you have it there.

Shaun VanWeelden
Shaun VanWeelden on 8 Nov 2013
Have them all point to the same callback and use the hObject variable to differentiate them. hObject is the current object being used and you can do your get/set stuff based on the hObject

Lorenzo
Lorenzo on 8 Nov 2013
Thanks both of you. I'm not sure I undestand though. Would you mind providing an example? Maybe I should have explained better how my GUI works in my original post. Every table is on its own but also, the results are returned to different text boxes, so when table1 is updated, the results are written to textbox1 and so on. Also, the result of the Nth table is written in the Nth element of a vector. Besides, not all the tables are enabled at first but table N is enables once table N-1 has been filled up. Is your solution still valid? Thanks!

Lorenzo
Lorenzo on 10 Nov 2013
If I understood correctly, when creating a new object one can define its create function by choosing an hObject value which can then be used to recognize objects in their edit functions. Is that correct?

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!