How to add drop down items based on a categorical array the user inputs in matlab gui app?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
% Value changed function: SELECTTEAMDropDown
function SELECTTEAMDropDownValueChanged(app, event)
teamname = string(app.SELECTTEAMDropDown.Value)
disp(app.station_names)
disp(app.trucklist)
% for i=1:12
% val{i}={app.station_names{i}}
% end
class((app.station_names))
app.SELECTSTATIONDropDown.Items=app.station_names
end
0 Kommentare
Antworten (1)
Deepak
am 6 Dez. 2024 um 8:59
Hi Prajwal,
To resolve the issue of populating dropdown items in a MATLAB GUI app based on a user-provided categorical array, first convert the categorical array to a cell array of strings using the “cellstr” function. This conversion allows to assign the array to the “Items” property of dropdown, ensuring the GUI can display the options correctly. Check if the array is categorical using “iscategorical” before conversion, and if it is already a string or cell array, assign it directly.
Below is the MATLAB code to achieve the same:
% Value changed function: SELECTTEAMDropDown
function SELECTTEAMDropDownValueChanged(app, event)
teamname = string(app.SELECTTEAMDropDown.Value);
disp(app.station_names);
disp(app.trucklist);
% Convert categorical array to cell array of strings
if iscategorical(app.station_names)
stationNamesCellArray = cellstr(app.station_names);
else
stationNamesCellArray = app.station_names; % Assume it's already a cell array or string array
end
% Update the dropdown items
app.SELECTSTATIONDropDown.Items = stationNamesCellArray;
end
Please find attached the documentation of functions used for reference:
iscategorical: www.mathworks.com/help/matlab/ref/iscategorical.html
I hope this will help in resolving the issue.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Tables 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!