Persistent variables not being initialized.

I am trying to initialize persistent variables in a Matlab function block in Simulink. I have used the debug mode to check the value of the variables. I find it strange that even after execution of the initialize statement, the variable is empty. Is there any reason for this to happen?

4 件のコメント

Birdman
Birdman 2018 年 4 月 20 日

What is your code to initialize your persistent variable?

Shubham Agarwal
Shubham Agarwal 2018 年 4 月 20 日
   if isempty(temp_alg)
        temp_alg = zeros(1,1);
    end
    if isempty(temp_fn)
        temp_fn = ones(1,1);
    end
Birdman
Birdman 2018 年 4 月 20 日
Also share your Simulink model please.
Shubham Agarwal
Shubham Agarwal 2018 年 4 月 20 日
However, I have been debugging it for some time and have found that the variables are actually getting initialized but on hovering over them in the debug mode, it's shown as empty. Also on printing the value of the variable in the debug mode, the value is empty. But if I assign its value to a return variable and check it on scope, then I see that it has been initialized. That's very weird and I have spent over 3 days trying to figure this out.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

質問済み:

2018 年 4 月 20 日

コメント済み:

2018 年 4 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by