基本的に定数と文字列の定義を含むスクリプトを呼び出すネストされた関数があります。これらの変数をベース ワークスペースに渡す必要があります。私はそれらをglobal
、最善の解決策ではないはずだと定義できることを知っていますよね?
関数の出力引数を使用する従来の方法は、私の場合は複雑すぎるようです。(実際には1回限りの呼び出しなので、コードを爆破したくありません)assignin
andを使用することを考えwho
ましたが、セル配列でもコンマ区切りのリストでも機能しないようです。おそらく、いくつかの構文の改良が欠けているだけです。
function myFunction()
myScriptWithDefinitions;
% who returns a cell array with all variables from my script
temp = who;
% now I try to assign these variables to my base workspace
% these are my attempts, none of them working
assignin('base',who);
assignin('base',temp{:});
assignin('base',{temp{:}});
...
end
名前のリストと値のリストの両方を実際に渡す必要があることは承知しています。さらにアイデアはありますか?
編集:次のようなもの
assignin('base',{'A','B'},{2,5})
% or
assignin('base',{'A',2},{'B',5})
機能しないためassignin
、一般的にはオプションではないと思います。