The model should generate 'N' number of editable input boxes using app design in MATLAB.
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
Manikanta Aditya
2024-3-27
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
采纳的回答
Malay Agarwal
2024-3-27
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!
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!