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!