SimulinkのMatlab functionで配列を保持する方法について
    17 views (last 30 days)
  
       Show older comments
    
    Kenjirou Oomori
 on 15 Mar 2020
  
    
    
    
    
    Commented: Toshinobu Shintai
    
 on 16 Mar 2020
            SimulinkでMatlab functionを使用し配列を計算。
その配列を次のステップでもMatlab functionで使用したいのですが、配列を保持する方法がわかりません。
Simulink で配列を保持する方法について教えていただきたいです。
0 Comments
Accepted Answer
  Toshinobu Shintai
    
 on 15 Mar 2020
        配列に限らず、Simulinkで変数を保持するためには「persistent」を使う必要があります。
関数の最初の方で以下のように記述します。
persistent a;
if isempty(a)
    a = zeros(3,1);
end
この場合「a」がstatic変数扱いとなり、次の計算ステップまで値を保持するようになります。
「if isempty」のところは、aの初期化を行っています。ここで任意の値に初期化することができます。初期化は必ず行ってください。
4 Comments
More Answers (0)
See Also
Categories
				Find more on Simulink Function in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
