Creating function variables to be filled with EditField Inputs

조회 수: 3 (최근 30일)
Brett
Brett 2023년 10월 13일
댓글: Florian Bidaud 2023년 10월 16일
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.

채택된 답변

Florian Bidaud
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.
  댓글 수: 2
Brett
Brett 2023년 10월 13일
So if I were to paste the rest of my script where you noted, would I need to define or adjust the variables elsewhere or could they just be taken as it?
Florian Bidaud
Florian Bidaud 2023년 10월 16일
They could be taken as it.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by