how use categorical in uitable

3 Ansichten (letzte 30 Tage)
shamal
shamal am 25 Jan. 2025
Kommentiert: shamal am 26 Jan. 2025
VNAMES={'On','Trading','L_S','Stat','PROVA','Cap','Perc','Draw_Sys'};
cat=categorical({'Fil';'Stat'});
VTYPES=[{'logical'},{'string'},{'string'},{'double'},{'double'},{'cat'},{'double'},{'logical'}];
T=table('Size',[nrows,numel(VNAMES)],'VariableTypes',VTYPES,'VariableNames',VNAMES);
Error using table (line 310)
Specify variable types as a string array or a cell array of character
vectors, such as ["string", "datetime", "double"].
i try to use in vtypes : {'cat'}..{cat}...{"cat"} but it give me an error

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 26 Jan. 2025
nrows = 5;
VNAMES={'On','Trading','L_S','Stat','PROVA','Cap','Perc','Draw_Sys'};
cat=categorical({'Fil';'Stat'});
VTYPES=[{'logical'},{'string'},{'string'},{'double'},{'double'},{'categorical'},{'double'},{'logical'}];
T=table('Size',[nrows,numel(VNAMES)],'VariableTypes',VTYPES,'VariableNames',VNAMES)
T = 5x8 table
On Trading L_S Stat PROVA Cap Perc Draw_Sys _____ _________ _________ ____ _____ ___________ ____ ________ false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false
Your problem was using 'cat' as the variable type name instead of 'categorical'
  3 Kommentare
Walter Roberson
Walter Roberson am 26 Jan. 2025
catty = categorical(["No", "No", "All", "Ranking", "No"]);
nrows = 5;
VNAMES={'On','Trading','L_S','Stat','PROVA','Cap','Perc','Draw_Sys'};
cat=categorical({'Fil';'Stat'});
VTYPES=[{'logical'},{'string'},{'string'},{'double'},{'double'},{'categorical'},{'double'},{'logical'}];
T=table('Size',[nrows,numel(VNAMES)],'VariableTypes',VTYPES,'VariableNames',VNAMES)
T = 5x8 table
On Trading L_S Stat PROVA Cap Perc Draw_Sys _____ _________ _________ ____ _____ ___________ ____ ________ false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false false <missing> <missing> 0 0 <undefined> 0 false
T.Cap = catty(:)
T = 5x8 table
On Trading L_S Stat PROVA Cap Perc Draw_Sys _____ _________ _________ ____ _____ _______ ____ ________ false <missing> <missing> 0 0 No 0 false false <missing> <missing> 0 0 No 0 false false <missing> <missing> 0 0 All 0 false false <missing> <missing> 0 0 Ranking 0 false false <missing> <missing> 0 0 No 0 false
The clue is "values within a cell array". You are trying to use cell array elements that are categorical, whereas the array at that point should just be categorical instead of cell array containing categorical.
betty1 = categorical(["No", "No", "All", "Ranking", "No"]);
betty = num2cell(betty1(:))
betty = 5x1 cell array
{[No ]} {[No ]} {[All ]} {[Ranking]} {[No ]}
T.Cap(1:5) = catty %works because the elements are already categorical
T = 5x8 table
On Trading L_S Stat PROVA Cap Perc Draw_Sys _____ _________ _________ ____ _____ _______ ____ ________ false <missing> <missing> 0 0 No 0 false false <missing> <missing> 0 0 No 0 false false <missing> <missing> 0 0 All 0 false false <missing> <missing> 0 0 Ranking 0 false false <missing> <missing> 0 0 No 0 false
T.Cap(1:5) = betty %fails because the elements are cell array of categorical
Error using . (line 507)
Right hand side of an assignment to a categorical array must be a categorical or text representing a category name.
shamal
shamal am 26 Jan. 2025
i solve problem with this solution:
app.UITable.Data=T;
app.UITable.ColumnName=["On";'Trading';"L/S";"Static";"PROVA";"Capitale $";"100% Distrib";"Draw_Sys"];
cat=categorical({'LS';'L';'S'});
cat1=categories(cat);
colu={'logical' 'char' 'char' 'char' {cat1{:}} 'char' 'char' 'logical'};

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange

Produkte


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by