Any way to do a multiple vector input?

9 visualizaciones (últimos 30 días)
triges
triges el 14 de Feb. de 2015
Respondida: John D'Errico el 14 de Feb. de 2015
Hi.
I'm developing a script that would ask the user for a number of variables and then ask for their vectors, something like:
if true
number_variables=input('how many variables?');
variables=sym('x',[1,number_variables]);
for i=1:length(variables)
fprintf('Type the name of the variable number %i',i);
variables(i)=input('=> ','s');
end
end
once the name of the variables are know, the user would be asked to input the vector of each one, I mean, the user would have to type directly
"variable1=[1 2 3 4]"
but it cannot be done with the input() command. I want each variable to be defined separately, is it possible?

Respuesta aceptada

John D'Errico
John D'Errico el 14 de Feb. de 2015
Well, yes, I'm sure it COULD be done, despite the confusing way you have described it.
You should NOT do it though. Code that creates variables like this will be difficult to debug. It will be confusing, nasty code.
Instead, learn to write and use functions. A function has input arguments. In fact, functions can have a variable number of input arguments, as many as you wish to provide and allow.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by