how to list variable name and values in the WS into a dropdown menu
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear all,
I would like to have a dropdown menu that allows me to find and select the variables that I have in my workspace. So that I can use the associated data for other operation.
For example in my workspace I have a variable A that is an array. I would like that in the dropdown menu I see A and when I select it I can use its values (the array)
So far I was able to list in the dropdown meny the variable name but those are just string and do not have the values.
How can I do?
With this code I found in the forum I can make the first part. But then the dropbown menu shows me the names of the varible only. I do not know how to associate to them te values and therefore in the last part in the "assignin" I just have a new variable called app.dataname = value but value is just the name of the variable from the dropdown and its value.
Please any help?
Thank you
Max
function update_menu(app, ~, ~)
vars = evalin('base', 'whos');
cell_array = cell(size(vars));
for i=1:length(vars)
cell_array{i} = vars(i).name;
end
app.PLUTODropDown.Items = cell_array;
end
function results = UIFigureCloseRequest(app, event)
% Close request function: UIFigure
stop(app.menu_timer);
delete(app.menu_timer);
delete(app)
end
function SavetoWorkspaceButtonPushed(app, event)
value = app.PLUTODropDown.Value;
app.dataname;
assignin('base',app.dataname,value) % app.dataname e' una stringa gia' quindi non devo mettere gli apici
end
0 commentaires
Réponses (1)
Oguz Kaan Hancioglu
le 30 Mar 2023
You can read any value from workspace using evalin command.
appArray = evalin('base','baseArray')
Unfortunately, in the app designer mosts of the menu are cell. After you read your array you need to create cell array in order to use in dropdown value. You can compare cell values or convert to double in order to use in your app.
9 commentaires
Oguz Kaan Hancioglu
le 4 Avr 2023
You can do it dynamically.
There is another solution. You can use assignin command to define your arrays in the base workspace. After than you can use them in the dropdown menu.
When you create a new array assign to base workspace.
assignin('base','myArrayName',myArray);
I hope it works.
Best
Voir également
Catégories
En savoir plus sur Develop uifigure-Based Apps dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!