Any way to do a multiple vector input?

9 次查看(过去 30 天)
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?

采纳的回答

John D'Errico
John D'Errico 2015-2-14
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by