In app designer add two "edit field (numeric)", name the first one editN and the second one editM. Next, add a button, named "Button". And finally add a Table named UITable. Delete all table columns.
Now we have an app that should look like this:
I think the easiest approach is to generate a table of size (num_row x num_col) with logical data type. If you add this table as data to an uitable, then the checkboxes are automatically added since the datatype is logical.
Add a ButtonPushed Callback to your button and paste the following code.
function ButtonPushed(app, event)
n = app.editN.Value;
m = app.editM.Value;
t = table( ...
'Size', [n,m], ...
'VariableTypes', repmat("logical", 1, m) ...
);
app.UITable.Data =t;
app.UITable.ColumnEditable = true;
app.UITable.ColumnName = string(1:m);
app.UITable.RowName = string(1:n);
end
If you type in the size and push the button, checkboxes are added to the table:
You can access the data (check box status) pretty easy by app.UITable.Data or convert it to an array (logical matrix) via
logicalMatrix = table2array(app.UITable.Data)
If you do not want to use a table, you could also add checkboxes programmatically, (e.g. inside a loop), but here you have to take care of positions by yourself:
for ii = 1:n
for jj = 1:m
cb(ii, jj) = uicheckbox(app.UIFigure, 'Position', aPosition{ii, jj})
end
end