필터 지우기
필터 지우기

Debug in coder.extrinsic

조회 수: 3 (최근 30일)
Qingyu
Qingyu 2020년 6월 15일
답변: Denis Gurchenkov 2023년 7월 14일
Hi, I use 'coder.extrinsic' in the 'Matlab function' block of Simulink.
However, the debugging is inconvenient.
Here is a simple example.
coder.extrinsic('abcd')
[c,d]=abcd(a,b)
If there is a bug in 'abcd.m', then the Simulink Diagnostic Viewer will show the corresponding error, say, 'size mismatch'. However, it does not show in which line the error is. If 'abcd.m' is a huge function, it would take a long time to locate the bug.
Is there a better way to debug extrinsic functions in Simulink?

답변 (1개)

Denis Gurchenkov
Denis Gurchenkov 2023년 7월 14일
There are two possible causes for an error in the extrinsic call.
  1. The error is in the body of this function.
  2. The error (size mismatch) happens when the return values of the function are assigned to the variables c and d.
For the first case, the way to debug is to put a breakpoint in the body of abcd, and then step through this function in MATLAB debugger. Note that because the call to abcd is extrinsic, this function is not generated to C code, and insted its source code is executed in the matlab interpreter, so breakpoints would work.
For the second case, you can just compare the return values of abcd (as you see in the debugger) to the sizes of c and d (those you can see in the compilation report). If the return values have bigger size (for instance, abcd returns a 3x3 array, whereas c is a scalar variable), that would explain the size mismatch error. To fix such an error, mark c as "coder.varsize" or pre-assign it to have the right size.

카테고리

Help CenterFile Exchange에서 Configure and View Diagnostics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by