필터 지우기
필터 지우기

if else statements with asking user for input

조회 수: 1 (최근 30일)
Zach Dunagan
Zach Dunagan 2017년 11월 10일
답변: Star Strider 2017년 11월 10일
My code is attached. Is there a way to only have one prompt at the beginning of the if else statements, instead of 2? I have 4 different equations solving for the same value (kv), except each equation is for different profiles.
Also I was also considering implementing a function file into the code. The second file is a function file. The function file calculates another variables 'sB'. The variable 'sB' is in the function file, while kv is in primary script.

답변 (1개)

Star Strider
Star Strider 2017년 11월 10일
I prefer the inputdlg (link) function.
You can replace your first two input statements with this:
prompt = {'Enter pitch diameter', 'Enter RPM'};
dlg_title = 'Input';
num_lines = [1 40];
default_ans = {'10', '1500'};
dn = inputdlg(prompt,dlg_title,num_lines,default_ans, [1 50]);
d = str2double(dn(1));
n = str2double(dn(2));
For your third input statement, I would use the related listdlg (link) function.

카테고리

Help CenterFile Exchange에서 Scope Variables and Generate Names에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by