Create a report information object for a code generation process that
fails. You then locate the part of MATLAB code that caused an error message.
Define the MATLAB function foo
:
Generate a static C library for foo
. Specify the input as a
string scalar. Export the code generation report information to the variable
info
in your base MATLAB workspace.
Code generation fails because a string scalar is not a valid input for the
MATLAB function svd
. The code generator creates a report
information object info
in the base MATLAB workspace.
The property info.Messages
is a two-dimensional array containing
descriptions of two code generation messages. Inspect the description of the first
message.
Message with properties:
Identifier: 'Coder:toolbox:unsupportedClass'
Type: 'Error'
Text: 'Function 'svd' is not defined for values of class 'string'.'
File: [1×1 coder.CodeFile]
StartIndex: 26
EndIndex: 33
To manually inspect the segment of MATLAB code that caused this error message, first display the text of the file
associated with this error
message.
'function b = foo(a)
b = svd(a,0);
end
'
Use getLineColumn
to locate the beginning and end of the part of
the code that caused the error message. The output startLoc
contains
the line and column indices of the first character of the code segment. The output
endLoc
contains the line and column indices of the last character
of the code
segment.
startLoc =
struct with fields:
Line: 2
Column: 5
endLoc =
struct with fields:
Line: 2
Column: 12
These
locations correspond to the beginning and the end of the function call
'svd(a,0)'
in the text of
foo.m
.