Debug Simulink MATLAB funciton block inside for each subsystem

8 ビュー (過去 30 日間)
Brad
Brad 2024 年 7 月 3 日
編集済み: Fangjun Jiang 2024 年 7 月 3 日
Is there a way to debug a Simulink MATLAB function block inside a For Each subsystem with the same capabilities that are provided when the function block is not in a for each subsystem?
When troubleshooting a Simulink MATLAB function block inside of a for each subsystem, my breakpoints pause program execution and take me to the breakpoint that activated, but I cannot access any of the variable values via hover or the MATLAB debug console.
The breakpoints seem to activate for every for each iteration (as expected) but I cannot see the values of any variables in the same way that I can when the function block is not in a for each subsystem.
  2 件のコメント
Fangjun Jiang
Fangjun Jiang 2024 年 7 月 3 日
Do you get the correct value if you type the variable name in the Command Window during the debugging mode?
Brad
Brad 2024 年 7 月 3 日
No. The console responds with a notice that it cannot find the variable specified. The workspace is also empty.

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

採用された回答

Fangjun Jiang
Fangjun Jiang 2024 年 7 月 3 日
編集済み: Fangjun Jiang 2024 年 7 月 3 日
Yes. I can confirm this behavior in R2022b.
When setting the loop number N to be 1, you will see the normal debugging behavior.
When setting the loop number N to be 2, you will see the normal "hover and show value" behavior every second time when the pause happened.
It is true that "The breakpoints seem to activate for every for each iteration (as expected)". But the breakpoints seem to be useless when it is not at the last iteration of the for-each subsystem execution.
The for-each subsystem has some limitations but I didn't find one that is related to this behavior.
There might be a reason for this. Any Mathworkers can provide an insight? Or this could be a shortcoming. Maybe the Mathowrks can improve it to meet this needed debugging behavior.
I tried to find a work-around for this. First, check the option "Show partition index output port" at the ForEach block and feed this signal to the MATLAB Function block so you can use it.
First, the conditional breakpoint did not work due to the same reason. If N is 10 and I set a conditional breakpoint when N==5, trying to observe certain values when iteration is at 6 (due to zero-based index), it gives error because N is not visible for debugging.
The other work-around is to add some code, such as if N==5, disp(SomeVariables), end. This seem to work. So the value is there in the code and it reflects the correct iteration. It is just not visible for debugging.
I hope this helps a little at least.
  1 件のコメント
Brad
Brad 2024 年 7 月 3 日
Thanks! I didn't realize that the last iteration had full debug behavior. That's very useful. I haven't pursued the disp strategy yet, but may have to if a MATLAB rep doesn't chime in with a better solution.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubsystems についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by