App Designer - How to generate dropdown lists using a cell array in the workspace
14 ビュー (過去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/522632/image.png)
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!