Any way to do a multiple vector input?

4 views (last 30 days)
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?

Accepted Answer

John D'Errico
John D'Errico on 14 Feb 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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!