1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MATLABの静的変数

Last updated at Posted at 2022-05-20

静的変数の設定。
Singletonなので、実質グローバル変数。運用時には注意。

静的データ

参考:静的データ

appdesinerの各methodからインスタンスとして開くclass

UseData.m
classdef UseData
   properties (Constant)
      Setting = SettingClass;
      Condition = ConditionClass;
   end
   % Class code here
end

上のUseData.m内のSettingとConditionのclass。
propertyは途中で増やせない。

SettingClass.m
classdef SettingClass < handle
   properties 
      SetA = 10;
      SetB = 20;
   end
end
ConditionClass.m
classdef ConditionClass < handle
   properties 
      ConditionA = 100;
      ConditionB = 200;
      ConditionC = 200;
   end
end

appdesinerのmethodで変数を使うときや、変更するとき。

matlab.m
h = UseData;    % インスタンス。最初やclear UseData後はコンストラクタ。
h.Setting.SetA = 30;    % 変数変更。
% SettingClassに直接入力しているコンストラクタ値は変わらない。
% 下記clear UseDataとしない限り、他のmethodで呼び出してもSetAは30が返る。

appdesinerを閉じるmethodに仕込む。

closefunction.m
clear UseData

この操作後、改めてh = UseData;とすると、h.Setting.SetAの値は10が返る。
appdesiner立ち上げmethodに入れたほうがよいかも。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?