matlab uitable: split columns into several rows
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I construct an uitable from a struct like:
% params is a struct
T = struct2table(params);
fields = fieldnames(params)';
fig = uifigure("Name", "Parameter Editor");
paramTable = uitable(fig);
paramTable.Data = T;
paramTable.ColumnName = fields;
Say the struct has a large number of columns, then they will be all next to each other in the uitable.
What I want is to have say maximum 10 columns next to each other to see all of them at first glance,
then the next 10 in a new row,
...
How can I do this?
0 Commenti
Risposte (1)
Shubham
il 12 Set 2023
Hi SA-W,
I understand you want to handle the large number of columns in such a way that at max 10 columns can be present in one row and next 10 can come to new row and so on.
To display the struct data in the uitable with a maximum of 10 columns per row, you can modify the code as follows:
% params is a struct
T = struct2table(params);
fields = fieldnames(params)';
% Create the uifigure and uitable
fig = uifigure('Name', 'Parameter Editor');
paramTable = uitable(fig);
% Set the Data and ColumnName properties of the uitable
paramTable.Data = T;
paramTable.ColumnName = fields;
% Calculate the number of rows and columns needed
numCols = size(T, 2);
numRows = ceil(numCols / 10);
% Set the Layout property of the uitable to 'grid' and specify the number of rows and columns
paramTable.Layout.Column = 10;
paramTable.Layout.Row = numRows;
% Set the ColumnWidth property of the uitable to a fixed value to display all columns uniformly
paramTable.ColumnWidth = repmat({100}, 1, numCols);
In this code, we calculate the number of rows and columns needed based on the number of columns in the struct. Then, we set the Layout.Column and Layout.Row properties of the uitable to specify the desired layout. Finally, we set the ColumnWidth property to a fixed value to display all columns uniformly.
Adjust the ColumnWidth value as needed to fit your data appropriately.
Vedere anche
Categorie
Scopri di più su Dialog Boxes in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!