Generate edit text boxes by providing their numbers in GUI
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to generate n number of edit text boxes by providing n as input in GUI. Is it possible?
For example,
User first provide value of n. Let it be 5
Then 5 edit boxes will be generated and then user provide values in them.
댓글 수: 1
Rik
2020년 1월 31일
This is fairly easy with a programmatic GUI, as you can create the uicontrol objects in a loop and determine the Position based on the number of inputs.
답변 (1개)
Kanishk
2024년 12월 23일
편집: Kanishk
2024년 12월 23일
Following Rik's comment, here is a simple function using loops to generate edit field.
function generateDynamicEditFields()
fig = uifigure('Name', 'Dynamic Edit Fields');
numField = uieditfield(fig, 'numeric', 'Position', [180 250 100 22]);
generateButton = uibutton(fig, 'push', 'Text', 'Generate', ...
'Position', [300 250 70 22], ...
'ButtonPushedFcn', @(btn, event) generateEditFields(fig, numField.Value));
end
function generateEditFields(parentFig, n)
delete(findall(parentFig, 'Type', 'uieditfield'));
for i = 1:n
uieditfield(parentFig, 'text', ...
'Position', [20, 250 - i*30, 350, 22]);
end
end
To add, you can use 'delete' and 'findall' to remove previously generated Edit fields.
delete(findall(parentFig, 'Type', 'uieditfield'));
Executing the 'generateDynamicEditFields' generates the follwing figure.
generateDynamicEditFields

You can learn more about 'uieditfield', 'delete' and 'findall' from the following commands.
web(fullfile(docroot, 'matlab/ref/uieditfield.html'))
web(fullfile(docroot, 'matlab/ref/delete.html'))
web(fullfile(docroot, 'matlab/ref/findall.html'))
Hope that helps!
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!