Hi Vishuka,
After going through your shared code, I added an extra property named DynamicInputBoxes_2 in order to store the values of age groups for each of the party. It is an 2D cell array because each party in a tab will contain its own set of age groups. I also added a button as for receiving the number of different age groups for different parties and accordingly added a callback function as follows:
function enterButtonPushed_3(app, tab, ElectionBox)
'Text', 'Enter age grps for each Party:', ...
'Position', [40, 325, 350, 22]);
numParties = app.editFields(ElectionBox).Value;
app.DynamicInputBoxes_2{ElectionBox} = cell(1,numParties);
initialPosition = [50, 320 , 50, 22];
initialPosition = initialPosition + [(j-1)*70,0,0,0];
numAgeGrps = app.DynamicInputBoxes_1{ElectionBox}(j).Value;
app.DynamicInputBoxes_2{ElectionBox,j} = gobjects(1,numAgeGrps);
fieldPosition = initialPosition +[0,-(k)*30, 0, 0];
app.DynamicInputBoxes_2{ElectionBox,j}(k) = uieditfield(tab,'numeric','Position', fieldPosition);
uibutton(tab, 'push', ...
'Position', initialPosition + [0,-(numAgeGrps+1)*30,0,0], ...
'ButtonPushedFcn', @(btn,event) fillDataFromExcel(app, ElectionBox, j));
In your original query, you also had mentioned regarding importing values for age groups. Assuming you wanted to import age group values for each party separately , I created a fillDataFromExcel as follows:
function fillDataFromExcel(app, ElectionBox, partyId)
[file, path] = uigetfile({'*.xlsx';'*.xls'}, 'Select an Excel file');
if isequal(file,0) || isequal(path,0)
excelFilePath = fullfile(path, file);
data = readmatrix(excelFilePath, 'Range', 'A:A');
numAgeGrps = app.DynamicInputBoxes_1{ElectionBox}(partyId).Value;
if numAgeGrps ~= numel(data)
warning('The number of data points in the Excel file does not match the number of input boxes.');
for k = 1:min(numAgeGrps, numel(data))
app.DynamicInputBoxes_2{ElectionBox, partyId}(k).Value = data(k);
Finally below are some outputs of the app working suiting your use case - (dynamic input box creation & import from excel).
The excel data used to fill age group for party-1 is as follows:
I have attached the source code with this post. I hope this modifications will be helpful for your usecase. Please note this is only a proof of concept prototype and it may need further UI modification or any missing/edge case analysis.