GUIDE: Duplicated elements without duplicated functions

1 次查看(过去 30 天)
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

回答(1 个)

David Sanchez
David Sanchez 2014-2-4
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.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by