Any way to do a multiple vector input?

조회 수: 9 (최근 30일)
triges
triges 2015년 2월 14일
답변: John D'Errico 2015년 2월 14일
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