Because generated C code initializes only non-zero elements,
you can efficiently initialize arrays by setting all elements to
0 directly in your C code. Then, use the generated C code
to initialize only nonzero elements. This approach enables efficient
initialization of matrices, especially sparse matrices.
Initialize the 3-by-3 identity matrix. First initialize the matrix with
all elements set to 0 in your C code. Then use the
generated C code to initialize the nonzero values.
Write C code to the file ccodetest.c by
specifying the File option. When writing to a file,
ccode optimizes the code by using intermediate
variables named t0, t1, and so on.
syms x
f = diff(tan(x));
ccode(f,'File','ccodetest.c')
t0 = pow(tan(x),2.0)+1.0;
Include the comment Version: 1.1 in the file by using
the Comments option. ccode uses
block comments.
Symbolic input, specified as a symbolic expression.
Name-Value Pair Arguments
Specify optional
comma-separated pairs of Name,Value arguments. Name is
the argument name and Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN.
'File' — File to write to character vector | string
File to write to, specified as a character vector or string. When
writing to a file, ccode optimizes the code by
using intermediate variables named t0,
t1, and so on.
'Comments' — Comments to include in file header character vector | cell array of character vectors | string vector
Comments to include in the file header, specified as a character
vector, cell array of character vectors, or string vector. Because
ccode uses block comments, the comments must
not contain /* or */.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.