グローバルワークスペ​ースのグローバル変数​をローカルワークスペ​ースに移動させること​は出来ますか?

8 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2017 年 5 月 12 日
回答済み: MathWorks Support Team 2017 年 5 月 12 日
グローバルワークスペースのグローバル変数をローカルワークスペースに移動させ、そこで継続的に使用することの可否を教えてください。
 

採用された回答

MathWorks Support Team
MathWorks Support Team 2017 年 5 月 12 日
実現する機能は提供されておりませんが、以下のような関数を作成することにより可能です。
 
function moveToLocal( str )
% MOVETOLOCAL Move a variable form the global to the local workspace
% str should be the name of the variable that is already in the global workspace
% that you wish to move to the local workspace of the calling function.
% The variable will still exist in the global workspace but in the local
% workspace of the calling function the variable will be scoped locally
eval(['global ' str]) % グローバル変数をローカル変数内に定義します。
k=eval(str); % グローバルワークスペースの変数を取得します。 
evalin( 'caller', ['clear ' str]); % 呼び出し側のワークスペースから値をクリヤします。 
assignin( 'caller', str, k); % 呼び出し側のローカル変数に値を代入します。
 

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange変数 についてさらに検索

製品


リリース

R2007a

Community Treasure Hunt

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

Start Hunting!