The model should generate 'N' number of editable input boxes using app design in MATLAB.
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Vahini Polishetty
am 27 Mär. 2024
Kommentiert: Vahini Polishetty
am 27 Mär. 2024
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 Kommentare
Manikanta Aditya
am 27 Mär. 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
Akzeptierte Antwort
Malay Agarwal
am 27 Mär. 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:
- Creating public properties in an App Designer App - https://www.mathworks.com/help/matlab/creating_guis/manage-properties-of-custom-ui-components-in-app-designer.html.
- Callbacks in App Designer - https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-for-gui-in-app-designer.html.
Hope this helps!
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!