problem with function output in the embedded matlab function

2 views (last 30 days)
Hi, I am trying to use discrete wavelet transform in the embedded matlab function, but I keep getting the next errors:
Function output 'A1' cannot be of MATLAB type.
Function 'Embedded MATLAB Function' (#18.0.230), line 1, column 1: "function [A1,D1]= fcn(u)"
Function output 'D1' cannot be of MATLAB type.
Function 'Embedded MATLAB Function' (#18.0.230), line 1, column 1: "function [A1,D1]= fcn(u)"
The code was:
function [A1,D1]= fcn(u)
eml.extrinsic('dwt','upcoef'); [cA1,cD1] = dwt(u,'db1'); A1 = upcoef('a',cA1,'db1',1,1); D1 = upcoef('d',cD1,'db1',1,1);
I hope somebody is able to help me to solve this problem
Thanks in advance
Nicolas

Answers (1)

Mike Hosea
Mike Hosea on 30 Aug 2012
This error means that you are trying to return the value from an extrinsic function call without having told the compiler what the output size and type is supposed to be. What it means for a function to be "extrinsic" is that you will call into MATLAB, which will generate an mxArray result. In order to generate the code that will convert the mxArray into a native data type in C, the eml compiler needs to know what will be in this mxArray before you call MATLAB. Note that extrinsic functions cannot be used for standalone code generation targets, but if your If you are only trying to run your code in Simulink, you can pre-declare the output before you call your function. I'm not familiar with the wavelet functions and don't have time right now to look them up, but an example would be a function y = foo(x1,x2) where we know that size(y) is size(x1) and class(y) is class(x2), and finally that the output is always complex. Then if foo is to be called as an extrinsic function we would declare it extrinsic at top
eml.extrinsic('foo');
and at the call site
y = complex(zeros(size(x1),class(x2))); % This is the output type.
y = foo(x1,x2); % Call foo in MATLAB and convert the mxArray that comes back.
-- Mike

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!