Any way to do a multiple vector input?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
triges
am 14 Feb. 2015
Beantwortet: John D'Errico
am 14 Feb. 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?
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 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.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!