how to list variable name and values in the WS into a dropdown menu
14 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Oguz Kaan Hancioglu
2023-3-30
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 个评论
Oguz Kaan Hancioglu
2023-4-4
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!