Debug Simulink MATLAB funciton block inside for each subsystem
2 次查看(过去 30 天)
显示 更早的评论
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
2024-7-3
Do you get the correct value if you type the variable name in the Command Window during the debugging mode?
采纳的回答
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subsystems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!