User input as a variable.

조회 수: 10 (최근 30일)
LeoAiE
LeoAiE 2021년 7월 19일
편집: LeoAiE 2021년 7월 19일
Hi everyone,
I have a pretty basic question here! I’m writing a script asking the user for an input and I want to use that input (string) as a variable and assign it a value. Basically, I want the user to name the variable and I will assign the values? Here is an illustration and my code
X = 100;
First_input = input('Please Enter your first variable\', 's');
Second_input = input('Please Enter your first variable\', 's');
Third_input = input('Please Enter your first variable\', 's');
(place_holder_for_whatever_the_first_input_is) = 1000 * x;
(place_holder_for_whatever_the_Second_input_is) = 2000 * x;
(place_holder_for_whatever_the_Third_input_is) = 1000 * x

채택된 답변

Walter Roberson
Walter Roberson 2021년 7월 19일
... for example what would happen if the user happened to name 'X' or 'x' as the variable, interfering with your use of that in your code?
  댓글 수: 1
LeoAiE
LeoAiE 2021년 7월 19일
편집: LeoAiE 2021년 7월 19일
Thanks Walter! Pretty helpful link.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by