| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Embedded MATLAB |
| Contents | Index |
y = eml.opaque(type,[value]);
Specifies the variable declared in the generated code.
Specifies the data type. Specify a C type defined in the user include file to avoid compilation errors. The C type provided must support assignment in C.
Specifies the data value declaration. Specify a C expression not dependent on Embedded MATLAB variables or functions.
If you do not define an initial value, you must initialize the value before using the data. Using the data without prior assignment can lead to compilation errors.
y = eml.opaque(type,[value]); declares data of the type type, and the optional initial value value. eml.opaque allows you to manipulate C data that the Embedded MATLAB subset does not recognize. type and value are treated as strings by Embedded MATLAB functions. Data initialized with eml.opaque can be:
Assigned to each other as long as their types are identical
An argument to eml.rref, eml.wref, or eml.ref
An input or output argument to eml.ceval
An input or output argument to a user-written Embedded MATLAB function
An input to a limited subset of Embedded MATLAB library functions
eml.opaque declares the type of a variable; it does not instantiate the variable. You can instantiate a variable using eml.ceval after declaring the variable type with eml.opaque. For example:
% Declare fp1 of type FILE *
fp1 = eml.opaque('FILE *');
%Create the variable fp1
fp1 = eml.ceval('fopen', cstring('filetest.m'), cstring('r'));The following example uses eml.opaque to declare a variable f as a FILE * type.
% This example returns its own source code by using
% fopen/fread/fclose.
function buffer = filetest
% Declare 'f' as an opaque type 'FILE *'
f = eml.opaque('FILE *', 'NULL');
% Open file in binary mode
f = eml.ceval('fopen', cstring('filetest.m'), cstring('rb'));
% Read from file until end of file is reached and put
% contents into buffer
n = int32(1);
i = int32(1);
buffer = char(zeros(1,8192));
while n > 0
% By default, Embedded MATLAB converts all constant values
% to doubles, so explicit type conversion to in32 is inserted.
n = eml.ceval('fread', eml.ref(buffer(i)), int32(1), ...
int32(numel(buffer)), f);
i = i + n;
end
eml.ceval('fclose',f);
buffer = strip_cr(buffer);
% Put a C termination character '\0' at the end of MATLAB string
function y = cstring(x)
y = [x char(0)];
% Remove all character 13 (CR) but keep character 10 (LF)
function buffer = strip_cr(buffer)
j = 1;
for i = 1:numel(buffer)
if buffer(i) ~= char(13)
buffer(j) = buffer(i);
j = j + 1;
end
end
buffer(i) = 0;eml.ceval, eml.ref, eml.rref, eml.wref
![]() | eml.nullcopy | eml.ref | ![]() |

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 |