how to use categorical in uitable

10 Ansichten (letzte 30 Tage)
Luca Re
Luca Re am 6 Okt. 2024
Kommentiert: Luca Re am 7 Okt. 2024
hi, I want to choose as value in a table field 'Fil' or 'Stat'
cat=categorical({'Fil';'Stat'});
name={'A','B'};
nrows=numel(name);
VNAMES={'Draw';'Filt_Stat'};
VTYPES=[{'logical'},{cat}];
T=table('Size',[nrows,numel(VNAMES)],'VariableTypes',VTYPES,'VariableNames',VNAMES); % empty t
T.Draw=repmat({true},nrows,1);
ct=cell(1, numel(name));
ct(:) = {cat{2}};
T.Filt_Stat=ct';
app.Portfolio_UITable.Data=T;
i get this error:
Error using table
Specify variable types as a string array or a cell array of character
vectors, such as ["string", "datetime", "double"].

Antworten (1)

Walter Roberson
Walter Roberson am 6 Okt. 2024
cat=categorical({'Fil';'Stat'});
That is categorical.
VTYPES=[{'logical'},{cat}];
That is a cell array that includes an element that is categorical.
T=table('Size',[nrows,numel(VNAMES)],'VariableTypes',VTYPES,'VariableNames',VNAMES); % empty t
VTYPES is a cell array that includes an element that is categorical. The VariableTypes parameter must be one of:
  • a string array
  • a cell array of character vectors
The result of categorical({'Fil';'Stat'}) is categorical, not a character vector.
When you set the VariableTypes, you can set an entry to be "categorical" or 'categorical' but you cannot set the entry to be a categorical
  2 Kommentare
Walter Roberson
Walter Roberson am 7 Okt. 2024
The VariableTypes parameter cannot hold any information about the details of categoricals.
What you might be thinking of is uitable . uitable() can have a ColumnFormat property, an element of which can be a cell array of character vectors that list category entries.
Luca Re
Luca Re am 7 Okt. 2024
I already solved it thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Categorical Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by