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

18 views (last 30 days)
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

Accepted Answer

Mario Malic
Mario Malic on 17 Feb 2021
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 Comments
Carlos Acasuso
Carlos Acasuso on 17 Feb 2021
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!

Sign in to comment.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!