Reading workspace variables into function

3 ビュー (過去 30 日間)
Mert
Mert 2011 年 7 月 7 日
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

採用された回答

Sean de Wolski
Sean de Wolski 2011 年 7 月 7 日
Don't do it!
  2 件のコメント
Paulo Silva
Paulo Silva 2011 年 7 月 7 日
MATLAB Answers needs sticky questions with the most common questions, this one being the first of them.
Mert
Mert 2011 年 7 月 7 日
My problem is to read variables from base workspace into a function with input command. Creating a struct array did not change the situation.
Undefined variable "S" or class "S.A1".

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by