Creating variable from string

3 ビュー (過去 30 日間)
Minh Nguyen
Minh Nguyen 2018 年 6 月 29 日
コメント済み: Star Strider 2018 年 6 月 29 日
Hello, looks like this question has been asked many times but I didn't find any answer. So I'm creating a function which read a text file and runs commands accordingly to what available in the text file. However, there are times when certain variables from the text file are not available within the function but are available in the base workspace (Like different config files for one instrument, and I don't want to reconnect every time). I'm trying to figure out something like this:
function MyFunction('a',b)
if(~exist('a','var')
<Make a variable named 'a' with value of 'b'>
end

採用された回答

Star Strider
Star Strider 2018 年 6 月 29 日
Experiment with the assignin (link) function.
This is generally not recommended. However it is the only way I am aware of to do what you want.
  2 件のコメント
Minh Nguyen
Minh Nguyen 2018 年 6 月 29 日
Thanks for the reply, I can see why it's not recommended, but for my case where I need is to either create an instrument object or use the one that's already available, this is pretty helpful to me. Anyways appreciate the help!
Star Strider
Star Strider 2018 年 6 月 29 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by