How to make an editable uitable with one categorical column ?
16 views (last 30 days)
Show older comments
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 ?
0 Comments
Accepted Answer
Luna
on 31 Jan 2019
Edited: Luna
on 31 Jan 2019
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 Comments
Luna
on 1 Feb 2019
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 :)
More Answers (0)
See Also
Categories
Find more on Develop uifigure-Based Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!