MATLAB: How to create variable number of Edit Text box in Matlab GUI

excelguimatlab gui

Hello all , My aim is to create a form , where I can provide values for the signals names and values given in the edit text box gets copied to the excel sheet corresponding to the signal name. For this,I want to Make a GUI where the number of edit text and static text Boxes depend on the size of an array. Suppose I have an array of 10 elements so I want 10 Edit text box and 10 static text box .Since the number of signals may change that is why I cannot fix the number of boxes. Please tell me how can I do it , or please suggest some other way to create forms in MATLAB , which depends on the number of signals.

Best Answer

N = number_of_elements;
for K = 1 : N
ypos = (N-K+1)*40;
h_static(K) = uicontrol('Style', 'text', 'String', sprintf('Signal %#d', K), 'Units', 'Pixels', 'Position', [20 ypos+20 80 20]);
h_edit(K) = uicontrol('Style', 'edit', 'String', '', 'Max', 2, 'Units', 'Pixels', 'Position', [120 ypos 300 40]); %if you want multiline
end
Adjust the position and control widths at need.