how use categorical in uitable
8 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2025-1-26
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)
Your problem was using 'cat' as the variable type name instead of 'categorical'
3 个评论
Walter Roberson
2025-1-26
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.Cap = catty(:)
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(:))
T.Cap(1:5) = catty %works because the elements are already categorical
T.Cap(1:5) = betty %fails because the elements are cell array of categorical
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!