Reading workspace variables into function
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I want a function to ask me the name of the variable from the base workspace to work on it. I have variables in the base workspace called A1, A2, A3. I want the function to read these variables into function by choice. I tried to assign the variables as global, however it doesn't seem to work.
Here's what I did;
function X name = input('Var?') y = name*5; end
I got this error message;
Error using ==> input Undefined function or variable 'X'.
--------------------------------------------------------------
If I wanted to do it with eval function I would have written;
function X name = input('Var?','s') y = eval(name)*5; end
However it is not a practical way to do it. Any suggestions?
Thanks, Mert
0 Kommentare
Akzeptierte Antwort
Sean de Wolski
am 7 Jul. 2011
Don't do it!
2 Kommentare
Paulo Silva
am 7 Jul. 2011
MATLAB Answers needs sticky questions with the most common questions, this one being the first of them.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Variables 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!