Generate edit text boxes by providing their numbers in GUI

2 visualizzazioni (ultimi 30 giorni)
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 Commento
Rik
Rik il 31 Gen 2020
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.

Accedi per commentare.

Risposte (1)

Kanishk
Kanishk il 23 Dic 2024
Modificato: Kanishk il 23 Dic 2024
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!

Categorie

Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by