User input as a variable.

26 visualizaciones (últimos 30 días)
LeoAiE
LeoAiE el 19 de Jul. de 2021
Editada: LeoAiE el 19 de Jul. de 2021
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

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Jul. de 2021
... 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 comentario
LeoAiE
LeoAiE el 19 de Jul. de 2021
Editada: LeoAiE el 19 de Jul. de 2021
Thanks Walter! Pretty helpful link.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by