App Designer - How to generate dropdown lists using a cell array in the workspace

18 ビュー (過去 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

採用された回答

Mario Malic
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 件のコメント
Carlos Acasuso
Carlos Acasuso 2021 年 2 月 17 日
That already worked, thanks! I want to try replace the evalin as you've suggested, I'll spend a bit more time to get that working. I actually have a .mat file in the directory from which the cell arrays for the lists could be extracted. Do you think it is better idea to load those and manipulate them in App Designer to prepare the lists? Have not tried it yet, but should work I hope!
Mario Malic
Mario Malic 2021 年 2 月 17 日
It should work, and it would be the most appropriate way to do so.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by