matlab uitable: split columns into several rows

5 次查看(过去 30 天)
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?

回答(1 个)

Shubham
Shubham 2023-9-12
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.
  1 个评论
SA-W
SA-W 2023-9-13
Thank you!
A short follow-up: Is there also a way to sort the columns/rows of the uitable by types? That is, grouping strings, floats, logical,...?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by