ColumnEditable problem with categorical

f = figure('Position', [100 100 752 250]);
t = uitable('Parent', f, 'Position', [25 50 700 200]);
t.ColumnName = {'Num1','Num2','Text'};
t.Data = {'b', 'q','JN'};
t.ColumnEditable=[true,true,true];
ret=categorical({'H';'L'});
t.ColumnFormat ={'bank' ret 'bank'};
Error setting property 'ColumnFormat' of class 'Table':
ColumnFormat definitions must be either 'numeric', 'logical', 'char', or be a popupmenu definition
Error in CANCELLA (line 10)
t.ColumnFormat ={'bank' ret 'bank'};

 採用された回答

Cris LaPierre
Cris LaPierre 2023 年 6 月 16 日

1 投票

You can't set the ColumnFormat value to be a categorical. It must be either 'numeric', 'logical', 'char', or be a popupmenu definition (character array).
Why not just do this?
f = figure('Position', [100 100 752 250]);
t = uitable('Parent', f, 'Position', [25 50 700 200]);
t.ColumnName = {'Num1','Num2','Text'};
t.Data = {'b', 'q','JN'};
t.ColumnEditable=[true,true,true];
ret={'H' 'L'};
t.ColumnFormat ={'bank' ret 'bank'};
Not sure what you want the 'bank' values to be. If you meant 'blank', use [] instead.
t.ColumnFormat ={[] ret []};
If you meant to have them be dropdown menu uptions for the first and third column, do this.
t.ColumnFormat ={{'bank'} ret {'bank'}};

5 件のコメント

piero
piero 2023 年 6 月 16 日
it give me an error :
Error setting property 'ColumnFormat' of class 'Table':
ColumnFormat definitions must be either 'numeric', 'logical', 'char', or be a popupmenu definition
Error in CANCELLA (line 12)
t.ColumnFormat ={[] ret []};
i want to have dropdown menu only the second element in table (the first and the third are blank)
Cris LaPierre
Cris LaPierre 2023 年 6 月 16 日
What version of MATLAB are you using?
Even simpler approach would be this:
f = figure('Position', [100 100 752 250]);
t = uitable('Parent', f, 'Position', [25 50 700 200]);
t.ColumnName = {'Num1','Num2','Text'};
t.Data = {'b', 'q','JN'};
t.ColumnEditable=[true,true,true];
t.ColumnFormat ={[] {'H' 'L'} []};
piero
piero 2023 年 6 月 16 日
>> version
ans =
'9.14.0.2254940 (R2023a) Update 2'
t.ColumnFormat ={[] {'H' 'L'} []};
no ...i want to use categorical because i import it from function..(there is a lot data)
this is an example but my progect is different
Cris LaPierre
Cris LaPierre 2023 年 6 月 16 日
Again, you can't use categoricals. It must be a char. If your data coming in is categorical, you must extract the categories and use that to set the ColumnFormat.
May something like this?
f = figure('Position', [100 100 752 250]);
t = uitable('Parent', f, 'Position', [25 50 700 200]);
t.ColumnName = {'Num1','Num2','Text'};
t.Data = {'b', 'q','JN'};
t.ColumnEditable=[true,true,true];
ret=categorical({'H';'L'});
cat = categories(ret);
t.ColumnFormat ={[] {cat{:}} []};
piero
piero 2023 年 6 月 16 日
thanks..correct

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDevelop Apps Programmatically についてさらに検索

質問済み:

2023 年 6 月 16 日

コメント済み:

2023 年 6 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by