| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Embedded MATLAB |
| Contents | Index |
[y =] eml.ceval('function_name', eml.wref(argO), ... un);
Variable passed by reference as a write-only output to the external C function called in eml.ceval.
[y =] eml.ceval('function_name', eml.wref(argO), ... un); passes the variable argO by reference as a write-only output to the external C function called in eml.ceval. You add eml.wref inside eml.ceval as an argument to function_name. The argument list can contain multiple eml.wref constructs. Add a separate eml.wref construct for each write-only argument that you want to pass by reference to function_name.
Caution The Embedded MATLAB subset assumes that a variable passed by eml.wref is write-only and optimizes the code accordingly. Consequently, the C function must write to the variable. If the variable is a vector or matrix, the C function must write to every element of the variable. Otherwise, results are unpredictable. |
Only use eml.wref in Embedded MATLAB code that you have compiled with emlmex or emlc. eml.wref generates an error in uncompiled M-code.
In the following example, an Embedded MATLAB function fcn has a single input u and a single output y, a 5-by-10 matrix. fcn calls a C function init to initialize the matrix, passing y by reference as a write-only output. Here is the Embedded MATLAB function code:
function y = fcn(u)
y = zeros(5,10,'int8'); %Constrain output to an int8 matrix
eml.ceval('init', eml.wref(y));The corresponding C function prototype looks like this:
void init(int8_T *x);
In this example:
Although the C function is void, eml.wref allows it to access, modify, and return a matrix to the Embedded MATLAB function.
The C function prototype defines the output as a pointer because it is passed by reference.
The Embedded MATLAB subset cannot infer the type of the output y, so you must set it explicitly—in this case to an int8 matrix, matching the C type int8_T. For a list of type mappings, see Mapping MATLAB Types to C.
Embedded MATLAB collapses matrices to a single dimension in the generated C code.
![]() | eml.varsize |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |