Duplicated elements in a GUI

1 回表示 (過去 30 日間)
Lorenzo
Lorenzo 2013 年 11 月 8 日
回答済み: Lorenzo 2013 年 11 月 10 日
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!

回答 (4 件)

Sean de Wolski
Sean de Wolski 2013 年 11 月 8 日
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 2013 年 11 月 8 日
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 2013 年 11 月 8 日
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 2013 年 11 月 10 日
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?

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by