How to access a variable in workspace with a string

13 ビュー (過去 30 日間)
Chaz
Chaz 2014 年 12 月 18 日
コメント済み: Francesco Alciati 2022 年 11 月 25 日
I'm trying to make a simple menu system. I have all the variables I need in the workspace, and I have the name of the variable I want to access stored as a string, how do I open the workspace variable using that string?
  3 件のコメント
Rik
Rik 2019 年 4 月 24 日
However, using eval is a bad idea.
(I have taken the liberty of adapting some of Stephen Cobeldick's thoughts on this topic) Introspective programing (e.g. eval, assignin and other functions like it) is slow, and the MATLAB documentation warns specifically against it. Using eval is slow, makes debugging difficult, and removes all code helper tools (code checking, syntax hints, code completion, variable highlighting, etc.). A longer discussion can be found here. If you are not an expert and you think you need eval, there are probably better solutions to your problem. Also, if you are not an expert, you might find interesting and helpful hints on this page (and if you are an expert, you can still learn from it).
Francesco Alciati
Francesco Alciati 2022 年 11 月 25 日
maronn ro carmine eval is medioeval

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

採用された回答

Chaz
Chaz 2014 年 12 月 18 日
Figured out how, used the eval() function.

その他の回答 (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