How to make an editable uitable with one categorical column ?

16 views (last 30 days)
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 ?

Accepted Answer

Luna
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
Hugo COSTE DOMBRE
Hugo COSTE DOMBRE on 1 Feb 2019
Thanks a lot !
I still have a warning but the code works now.
Luna
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 :)

Sign in to comment.

More Answers (0)

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!