return value of categorical array in uitable- Matlab App Designer

4 ビュー (過去 30 日間)
Niklas Högemann
Niklas Högemann 2021 年 5 月 7 日
回答済み: Riya 2025 年 4 月 24 日
Hi Guys, im just working on a GUI with Matlab App Designer. Ive added some UITables with categorical arrays to have drop menues in my tables. Therefore i defined the cells like "cell = categorical({'on'}, {'on','off'})", to have a default value in the drop down. The issue is that the return value of the cell is "1x1 categorical" when im not changing the default value, but if i made any changes on the drop down i get only a char value from the cell. Why does matlab do this cast operation? Is there a way to get a categorical array for any case?
Best regards

回答 (1 件)

Riya
Riya 2025 年 4 月 24 日
Hi, 
I understand that you want to return categorical values when the dropdown value changes.
It happens because MATLAB treats dropdown values as editable strings instead of preserving their data type.
To consistently return categorical values, you can consider adding “CellEditCallbackfunction for yourUITablecomponent:
function UITable_CellEdit(app, event)
row = event.Indices(1);
col = event.Indices(2);
newValue = event.NewData;
% If the column is supposed to be categorical, convert back
if col == 1 % assuming first column is categorical
validCats = {'on', 'off'};
app.UITable.Data{row, col} = categorical({newValue}, validCats);
end
end
If you have multiple categorical columns, you can maintain a map or array and apply the conversion accordingly.
For more information about callbacks in App designer, refer the following documentation:
web(fullfile(docroot, 'matlab/creating_guis/write-callbacks-for-gui-in-app-designer.html')) 

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by