Creating function variables to be filled with EditField Inputs
3 次查看(过去 30 天)
显示 更早的评论
I have an existing script that runs based on set numbers. I am trying to create a GUI that will allow the user to replace those numbers from the interface rather than editing the actual script. I was trying to assign the values from the EditField numeric to variables which could then be placed into the script (rewrittten as a function for external calling for the same path).
I tried assinging that neccessary variables for the function myfunc(q,w,e,r,t,y,u,i,o). I tried assigning the variables like below to the existing internal names (dt = q rather than dt = 2000 like the original script).
dt = q;
tmin = w;
istart = e;
iend = r;
th_high = t;
th_medium = y;
th_low = u;
spot_rad=i;
rem_size=o
I am a novice to matlab and app designer as a whole. Thank you in advance.
0 个评论
采纳的回答
Florian Bidaud
2023-10-13
编辑:Florian Bidaud
2023-10-13
Hi
My guess is you don't need the app designer for such a simple thing. you could simply use the function input.
So basically:
dt = input('dt = ');
tmin = input('tmin = ');
istart = input('istart = ');
iend = input('iend = ');
th_high = input('th_high = ');
th_medium = input('th_medium = ');
th_low = input('th_low = ');
spot_rad = input('spot_rad = ');
rem_size = input('rem_size = ');
If you really want to use app designer:
You need to create edit fields and a button like this for example :
Then create a Callback on the button like follows:
Then you can assign your variables from the edit fields in the push button callback function:
% Button pushed function: RunCodeButton
function RunCodeButtonPushed(app, event)
dt = str2double(app.dtEditField.Value);
tmin = str2double(app.tminEditField.Value);
istart = str2double(app.istartEditField.Value);
% Write the rest of you script here
end
If you then want to use these variables in a completly external script, my advise would be to save them in a .mat file with save, and load them back in the external script.
更多回答(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!