How to use mex files in MATLAB Function block?
Show older comments
Hi,
I am using ammonia-water thermodynamic properties in MATLAB using routines in C. When modelling dynamic systems in Simulink, I need to repeatedly call these property routines. I was using Matlab Interpreted Function Block till now. Lately, I read that replacing these with MATLAB Function block can speed up the simulations. But, when I call the property routines from within the MATLAB Fcn Block, I get an error. The code inside the block looks like this, with u1,u2,u3 being the different input properties.
function y = fcn(u1,u2,u3)
%#codegen
y = XNH3H2O('TPQ_H',u1,u2,u3);
The errors I get are:
1. Only MATLAB files are supported for code generation. Unsupported file extension 'mexw64' for 'D:/Work/XNH3H2O.mexw64'.Function'MATLAB Function' (#49.41.66), line 3, column 5:"XNH3H2O('TPQ_H',u1,u2,u3)"Launch diagnostic report. (coder error)
2. Error in port widths or dimensions. Output port 1 of 'Function_Test_2/MATLAB Function/u2' is a one dimensional vector with 1 elements. (block error)
3.Errors occurred during parsing of MATLAB function 'MATLAB Function'(#48) (Block error)
Answers (1)
Kaustubha Govind
on 21 Mar 2013
0 votes
You will need to declare MEX-functions using coder.extrinsic, just like you would for other functions that are not supported for code-generation.
Categories
Find more on Performance in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!