SimulinkのMatlab functionで配列を保持する方法について

16 views (last 30 days)
SimulinkでMatlab functionを使用し配列を計算。
その配列を次のステップでもMatlab functionで使用したいのですが、配列を保持する方法がわかりません。
Simulink で配列を保持する方法について教えていただきたいです。

Accepted Answer

Toshinobu Shintai
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
Kenjirou Oomori
Kenjirou Oomori on 16 Mar 2020
お騒がせしてすみません。
新たにブロック線図を作り直したら、無事実行することができました。
ありがとうございました。
Toshinobu Shintai
Toshinobu Shintai on 16 Mar 2020
安心しました。こちらこそありがとうございます。

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!