How to create a number of "Edit Text" feilds in a GUI, depending on the user input given in the GUI through an "Edit text" field itself?
조회 수: 3 (최근 30일)
이전 댓글 표시
I am trying to create a GUI in which there is a single Editable text field and a Push button. Depending upon the input number i give in the text field i need that many number of new Editable text fields created in the GUI. For example, inside the text field if i give input number as 5 and I push the button, i need 5 new editable text fields to be created.Is it possible to be done using uicontrols?
댓글 수: 0
답변 (2개)
Grzegorz Knor
2011년 9월 2일
Yes, it is possible :) Look at the example:
function test
e = uicontrol('Style','Edit','Units','Normalized','Position',[.4 .5 .2 .1]);
uicontrol('Style','PushButton','Units','Normalized',...
'Position',[.4 .3 .2 .1],'String','Create','Callback',@b_clbck);
function b_clbck(src,evnt)
n = str2double(get(e,'String'));
create_figure(n)
end
function create_figure(n)
figure('Units','Normalize','Name','New Figure')
for k=1:n
uicontrol('Style','Edit','Units','Normalized',...
'Position',[.4 k/n-.75/n .2 .75/n],'String',num2str(k));
end
end
end
댓글 수: 0
Paulo Silva
2011년 9월 2일
function testui
hp = uicontrol('Style', 'pushbutton', 'String', 'do it',...
'Position', [1 150 60 60], 'Callback', @doit);
he = uicontrol('Style', 'edit', 'String', '',...
'Position', [61 150 60 60]);
function doit(obj,ev)
n=str2num(get(he,'string'));
for m=1:n
hea(m)=uicontrol('Style', 'edit', 'String', '',...
'Position', [60*m-59 80 60 60]);
end
end
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 String Parsing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!