App Designer, how to use value of DropDown in external function file
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MLP
am 14 Sep. 2020
Bearbeitet: Mario Malic
am 18 Sep. 2020
Hello everyone, currently I am working on App Designer and need to use the DropDown item in order to be able to select which expression I want the calculations to proceed with. I have created a separate .m file which involves an if statement. If the DropDown value (Type) equals 1, do this expression, if it equals 2, then this other. I am getting the following error "Output argument "Rad_fin" (and maybe others) not assigned during call to "OgiveTypeAPP"". I call the outputs on app designer as follows:
[Rad_fin,Rad_tip,Rad_rear,Rad] = OgiveTypeAPP(dist_fin,DIST_tip,DIST_rear,DIST); %All inputs are specified on the app.
On app desginer I have stored the value of the dropdown as:
global Type; Type = app.DropDown.Value;
Below is a screenshot of the settings for the drop down and the external .m function I am using.
function [Rad_fin,Rad_tip,Rad_rear,Rad] = OgiveTypeAPP(l,m,n,o)
global Rmax
global L
global Type
if Type == 1
Rad_fin = Rmax*sqrt(l/L);
Rad_tip = Rmax*sqrt(m/L);
Rad_rear = Rmax*sqrt(n/L);
Rad = Rmax*sqrt(o/L);
elseif Type == 2
Rad_fin = Rmax*(l/L).^(0.75);
Rad_tip = Rmax*(m/L).^(0.75);
Rad_rear = Rmax*(n/L).^(0.75);
Rad = Rmax*(o/L).^(0.75);
end
end
0 Kommentare
Akzeptierte Antwort
Mario Malic
am 14 Sep. 2020
Bearbeitet: Mario Malic
am 15 Sep. 2020
Quick, delete the line with global variable before MATLAB police comes! Don't use global variables, unless there is really a need for it.
First of all, if you will use your variables in external functions, use the as properties, there is an option called Create property - public and define it.
Rmax = 5; % or Rmax = []
Similarly for char array: Type ='';
You can access or change the property value by typing
app.Rmax
In App designer create a button and a callback. Within it call your external function and pass the whole app (or only needed variables)
ExternalFunction(app)
And within the external function access the variables/properties as mentioned above.
2 Kommentare
Mario Malic
am 15 Sep. 2020
Bearbeitet: Mario Malic
am 18 Sep. 2020
I am not sure why didn't you get an error in your App Designer since Value can only be equal to Items (maybe I am wrong). In your example
DropdownMenu.Items = {'Power Law n = 0.5; Power Law n = 0.75'};
DropdownMenu.Value = 'Power Law n = 0.5'; % Must be one of the Items
ItemsData is a number that is associated with Items, you set there already 1 and 2.
Therefore
DropdownMenu.ItemsData = 1 - corresponds to DropdownMenu.Items{1} = 'Power Law n = 0.5' and DropdownMenu.Value(1) = 'Power Law n = 0.5';
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!