How to make an editable uitable with one categorical column ?

16 次查看(过去 30 天)
Hello,
I am trying to create an app with an uitable which uses a dropdown as a first row and then several numeric cells that I would like to be editable by the user. Following the exemples of the matlab website i first create a table with the right configuration and then create a uitable and set the data of the uitable equal to the first table :
Color = {'red'; 'red'; 'green'};
width = {10; 20; 30};
height = {100; 200; 300};
tableData = table(Color, width, height);
tableData.Color = categorical({'red'; 'red'; 'green'}, {'red'; 'white'; 'yellow'; 'green'});
uif = uifigure();
uit = uitable('Parent', uif);
uit.Data = tableData;
uit.ColumnEditable = true(1,3);
I then receive this warning :
Warning: ColumnEditable value can be true only for char, string, double, logical, datetime and categorical columns.
I have tried to specify the ColumnFormat :
Color = {'red'; 'red'; 'green'};
width = {10; 20; 30};
height = {100; 200; 300};
tableData = table(Color, width, height);
tableData.Color = categorical({'red'; 'red'; 'green'}, {'red'; 'white'; 'yellow'; 'green'});
uif = uifigure();
uit = uitable('Parent', uif);
%%%%%%%%
uit.ColumnFormat = {'char', 'numeric', 'numeric'};
%%%%%%%%
uit.Data = tableData;
uit.ColumnEditable = true(1,3);
And i get the following warning :
Warning: ColumnEditable value can be true only for char, string, double, logical, datetime and categorical columns.
Warning: 'ColumnFormat' value has no effect when 'Data' value is a table array.
And the uitable can not be edited except for the first column in both case. What am I doing wrong ?

采纳的回答

Luna
Luna 2019-1-31
编辑:Luna 2019-1-31
The reason is the uitable's 2nd and 3rd columns are cell array.
You should create them as double arrays like below with brackets not with curly braces:
width = [10; 20; 30];
height = [100; 200; 300];
  2 个评论
Luna
Luna 2019-2-1
Comment out this line it is useless now, since your data is already a table type. So you won't get the warning message anymore.
% uit.ColumnFormat = {'char', 'numeric', 'numeric'};
Please accept answer if it works correctly :)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by