Clear Filters
Clear Filters

The model should generate 'N' number of editable input boxes using app design in MATLAB.

8 views (last 30 days)
I'm creating an app in app designer using Matlab. if I have given my input as '5' in my editfield text, I has to get '5' number of input boxes, After the model creates 5 input boxes, those boxes should be editable where I can give required values in that boxes.
  2 Comments
Manikanta Aditya
Manikanta Aditya on 27 Mar 2024
To generate a dynamic number of editable input boxes in App Designer, you can use a combination of uifigure, uigridlayout, and uieditfield components.
function createInputBoxes(numBoxes)
% Create the app figure
appFig = uifigure('Name', 'Dynamic Input Boxes', 'Position', [100 100 300 300]);
% Create a grid layout to hold the input boxes
gridLayout = uigridlayout(appFig, [numBoxes 1]);
% Create an array to store the uieditfield components
inputBoxes = uieditfield(numBoxes, 'numeric');
% Add the input boxes to the grid layout
for i = 1:numBoxes
gridLayout.RowHeight{i} = 'fit';
gridLayout.ColumnWidth{1} = 'fit';
gridLayout.add(inputBoxes(i), i, 1);
end
end
Vahini Polishetty
Vahini Polishetty on 27 Mar 2024
Thanks for the Code, but I tried using the code in app design the input boxes are not generating for the given editfield value.

Sign in to comment.

Accepted Answer

Malay Agarwal
Malay Agarwal on 27 Mar 2024
Hi Radha,
I understand that you want to add N editable input fields to an app in App Designer, where N is a user-provided input.
I have attached a sample App Designer app in the answer. The app has the following components:
  • A numeric edit field.
  • A button.
There is also a public property called "DynamicInputBoxes", which is a cell array to store the generated editable input boxes. The user can enter a value in the numeric field, specifying the number of required editable input boxes. They can then click on the button to generate the boxes. The button is attached to a callback which reads the value of the numeric field and adds the required number of boxes:
function CreateInputFieldsButtonPushed(app, event)
% NumInputBoxes is the numeric edit field
numBoxes = app.NumInputBoxes.Value;
% Delete any existing input boxes
if ~isempty(app.DynamicInputBoxes)
for i=1:length(app.DynamicInputBoxes)
delete(app.DynamicInputBoxes{i});
end
app.DynamicInputBoxes = {};
end
% Initialize a cell array to store the handles to the input boxes
app.DynamicInputBoxes = cell(numBoxes, 1);
% Define initial position of the first input box
initialPosition = [100, 100, 100, 22]; % [x, y, width, height], adjust as needed
for i = 1:numBoxes
% Calculate position for the current input box
fieldPosition = initialPosition + [0, (i-1)*30, 0, 0]; % Adjust spacing as needed
% Create the input box
app.DynamicInputBoxes{i} = uieditfield(app.UIFigure, 'text', 'Position', fieldPosition);
end
end
Please make changes in the callback according to your requirements.
You can refer to the following resources for more information:
Hope this helps!

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!