UITable with both char and numeric data

14 次查看(过去 30 天)
I know you can have a UITable with all cell array data, and you can have one with all numeric data, but I want a mix of both in the same UITable, and I also want to allow the user to Sort the column data in an App Design GUI. If I create all cell array data, having my numeric data represented as cell arrays, and I click the Sort feature at the top of the column, it will not properly sort the data numerically. For example, if my numeric column is 4e5, 8e6, 1e7, it will sort as 1e7, 4e5, 8e6, whereas I want it sorted as 4e5, 8e6, 1e7. How do I create a UITable with mixture.
This site shows you can customize the format of a UITable with all numeric: https://www.mathworks.com/help/matlab/ref/format.html#btiwmh5-1-style
But it seems, I cannot have a mixture like this:
app.UITable.ColumnFormat = {'char','shortE','char','shortE','char'};
Maybe a future version of Matlab could allow this.
Otherwise a work-around is to create a function that sorts the numeric columns: UITableDisplayDataChanged(app, event), by converting the cell array data to numeric, then sorting, then converting numeric back to cell to display in the table.

采纳的回答

Mike D.
Mike D. 2020-10-5
I think I figured it out. The Data property must be Cell array which can be a mixture of data types:
data = {'text1', 4e6, 'file1', 5e-6, 'file30'; 'text33', 7e3, 'file345', 1e-4, 'file 13'; 'text888', 1e8, 'file 345', 9e-8, 'file 1333'};
app.UITable.Data = data;
app.UITable.ColumnFormat = {'char','shortE','char','shortE','char'};
Creating this data variable in a for-loop can be done like this:
for j = 1 : numel(categ)
data(j,:) = {categ{j}, temperature(j), fileNameT{j}, pressure(j), fileNameP{j}};
end
The values in the cell array must be numeric, logical or char. They can't be cell array or categorical.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Import and Analysis 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by