How to make an editable uitable with one categorical column ?

16 visualizaciones (últimos 30 días)
Hugo COSTE DOMBRE
Hugo COSTE DOMBRE el 31 de En. de 2019
Comentada: Luna el 1 de Feb. de 2019
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 ?

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by