coder.read
Syntax
Description
In your MATLAB® code for which you intend to generate C/C++ code, use the
coder.read
function to read data from .coderdata
files. The generated code performs the data read at run time.
To store your data in a .coderdata
file, use the coder.write
function in
MATLAB execution.
Each .coderdata
file contains a type header that
specifies the type and size of the data stored in the file. The coder.read
function uses this information when interpreting the contents of the file.
reads from the dataFromFile
= coder.read(filename
)filename.coderdata
storage file and returns the data
stored within the file. This syntax works for a constant filename
input
only. The file that this name represents must exist in your current folder during code
generation
You can use the coder.write
function to change the data contained
in filename.coderdata
before you run the generated code. However, the
type and size of data contained in filename.coderdata
must be the same at
compile time and run time.
uses the type and size information contained in dataFromFile
= coder.read(filename
,TypeHeaderFrom=typeHeaderFilename
)typeHeaderFilename
to
interpret the data in filename
. The
typeHeaderFilename
argument must be a compile-time constant and the
file that this name represents must exist in your current folder during code generation. The
code generator obtains the type and size information from
typeHeaderFilename
at compile time.
The code generated for the coder.read
function can read any
.coderdata
file at run time, as long as the type and size of the
contained data is consistent with the compile-time type and size information that you supply
using the typeHeaderFilename
file.
[
suppresses run-time errors during a read operation. If
any errors occur, dataFromFile
,errID
] = coder.read(___)coder.read
returns
the first error as errID
. The dataFromFile
argument
returns the unusable file content. Use this syntax to test the generated code for targets
for which run-time errors are disabled.
Examples
Input Arguments
Output Arguments
Extended Capabilities
Version History
Introduced in R2023a
See Also
coder.write
| coder.load
| fread
| fwrite
| fscanf
| fprintf
Topics
- Perform Data Read and Write Operations in Generated Code (MATLAB Coder)