App Designer - How to generate dropdown lists using a cell array in the workspace
17 次查看(过去 30 天)
显示 更早的评论
Hello,
I am quite beginner with Matlab overall, and just started also using App Designer. I am trying to achieve something quite simple:
Being able to input as the items list in a list box a cell array that already exists in my workspace.
I have already brought the cell array into App Designer by using the following code:
function startupFcn(app, Specs_FARB_FW43_List)
Specs_FARB_FW43_List = evalin('base','Specs_FARB_FW43_List'); % varName is in MATLAB base workspace
end
and also stating it as a 'property', what should allow me to access it from other functions within this app.
properties (Access = private)
Specs_FARB_FW43_List % FARB Options List
end
My question is then, since the code where the list is stated is shaded, can't be modified, and the only way to specify the list's elements is in the 'Inspector' tab, I can't find a way to make this work.
Thanks in advance for your help.
Carlos
0 个评论
采纳的回答
Mario Malic
2021-2-17
Hi Carlos,
It's not possible to change the code in grey area. You can leave the default component values and change them in the startupFcn. I would highly advise you to not use evalin, as everyone else would in this forum. You are probably running your app from the script, or function - place your code in or call the functions in App Designer directly. I think you can also run scripts in App Designer (I have never tried it), you will not see the variables unless you're in debugging mode, which may cause issues in debugging the app later, asking yourself, where does this variable come from, etc.
function startupFcn(app)
% calling the function from the .m file
Specs_FARB_FW43_List = myfun1();
app.ListFarb.Items = Specs_FARB_FW43_List;
end
You can also create a "helper function"
methods
function app.results = myfun2()
% some code
% - results can be structure type and you can place all your variables of interest in it
% - set the output of the function to be the property so you can access it from anywhere
end
end
2 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!