How can I perform mathematical operations using integers in the Embedded MATLAB function block?
5 views (last 30 days)
Show older comments
My model includes an Embedded MATLAB Function block, in which I attempt to perform mathematical operations using data of type integer (e.g., int8, uint8, int16, uint16, etc.). When I simulate my model, the following error is returned:
Expected either a logical, char, single, or double.
Found a int8.
Function 'Embedded MATLAB Function' (#48.131.133), line 5, column 6:
"x1"
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
This enhancement has been incorporated in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
The ability to perform mathematical operations using integers in an Embedded MATLAB function block is not available in Simulink. This is stated as a caveat in the documentation for the Embedded MATLAB function block under the "Data Type Support" section, available by typing the following at the MATLAB 7.0 (R14) prompt:
web([docroot '/toolbox/simulink/slref/embeddedmatlabfunction.html'])
To work around this issue, perform mathematical operations using data of type double or single; afterwards convert the result to an integer, as accomplished with the following code:
y = int8((single(x1)+single(x2))/single(4));
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!