GUIDE: Duplicated elements without duplicated functions

2 views (last 30 days)
Dear all, I'm writing a GUI in GUIDE with a lot of duplicated elements. I have 20 tables and 20 textboxes. Depending on the data entered in table_i the value of text_box_i is updated accordingly. Every text box depends on the corrisponding table only and the calculation behind each table+text_box pairing is the same.
What I have at the moment is:
function uitable_1_CellEditCallback(hObject, ~, handles)
c=get(hObject,'Data');
set(handles.text_box_1,'String', num2str(c*2)
This is for table+text_box 1. Since I have 20 pairings, this is repeated 20 times thus making my code long and boring to modify (every small change has to be repeated 20 times...)
Since the only change in the code is the number of the table (which is the same number for the text box), I was wondering if there was any way to do this by having one piece of code only. Something such as (but of course different than):
for i=1:20
function uitable_i_CellEditCallback(hObject, ~, handles)
c=get(hObject,'Data');
set(handles.text_box_i,'String', num2str(c*2)
end
Thanks!
Lorenzo

Answers (1)

David Sanchez
David Sanchez on 4 Feb 2014
Every object within your GUI has to have its own callback function, and these have to be defined in your code. You have to code all your callbacks.

Categories

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

Community Treasure Hunt

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

Start Hunting!