embedded matlab function error

1 view (last 30 days)
Hello everyone,
i used in may simulink model the Embedded MATLAB Function. Embedded MATLAB Function occurs error when it is running and error message is
"Function output 'x' cannot be of MATLAB type.
Function 'Embedded MATLAB Function' (#748.0.2126), line 1, column 1:
"function x =melbankmm(p,n,fs,fl,fh)"
Matlab version is v7.8.0(R2009a)
code is following:
*****************************************************************************
function x =melbankmm(p,n,fs,fl,fh)
%MELBANKM determine matrix for a mel-spaced filterbank [X,MN,MX]=(P,N,FS,FL,FH,W)
%
% Inputs: p number of filters in filterbank
% n length of fft
% fs sample rate in Hz
% fl low end of the lowest filter as a fraction of fs (default = 0)
% fh high end of highest filter as a fraction of fs (default = 0.5)
% w any sensible combination of the following:
% 't' triangular shaped filters in mel domain (default)
% 'n' hanning shaped filters in mel domain
% 'm' hamming shaped filters in mel domain
% 'z' highest and lowest filters taper down to zero (default)
% 'y' lowest filter remains at 1 down to 0 frequency and
% highest filter remains at 1 up to nyquist freqency
% If 'ty' or 'ny' is specified, the total power in the fft is preserved.
%
% Outputs: x a sparse matrix containing the filterbank amplitudes
% If x is the only output argument then size(x)=[p,1+floor(n/2)]
% otherwise size(x)=[p,mx-mn+1]
% mn the lowest fft bin with a non-zero coefficient
% mx the highest fft bin with a non-zero coefficient
%
% To plot filterbanks e.g. plot(melbankm(20,256,8000)')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
eml.extrinsic('sparse');
w='m';
f0=700/fs;
fn2=floor(n/2);
lr=log((f0+fh)/(f0+fl))/(p+1);
% convert to fft bin numbers with 0 for DC term
bl=n*((f0+fl)*exp([0 1 p p+1]*lr)-f0);
b2=ceil(bl(2));
b3=floor(bl(3));
b1=floor(bl(1))+1;
b4=min(fn2,ceil(bl(4)))-1;
pf=log((f0+(1:127)/n)/(f0+fl))/lr;
fp=floor(pf);
pm=pf-fp;
k2=b2-b1+1;
k3=b3-b1+1;
k4=b4-b1+1;
r=[fp(4:127) 1+fp(1:107)];
c=[4:127 1:107];
v=2*[1-pm(4:127) pm(1:107)];
mn=b1+1;
mx=b4+1;
v=1-0.92/1.08*cos(v*pi/2);
x=sparse(r,c+mn-1,v,p,1+fn2);
**************************************************************************
please help me
best regard
  2 Comments
Walter Roberson
Walter Roberson on 25 Jul 2012
It appears to me that embedded matlab does not support sparse. I find specific documentation for that at the time that embedded matlab was introduced, but it is not impossible it was added later. I do see at least some explicit restrictions on sparse in current documentation, such as http://www.mathworks.com/help/toolbox/simulink/slref/simulink.runtimeblock.html
latsi lab
latsi lab on 25 Jul 2012
thinks walter robenson for you answer, but how can i solved this problem

Sign in to comment.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 25 Jul 2012
Edited: Kaustubha Govind on 25 Jul 2012
Walter is correct - sparse matrices are documented amongst the MATLAB Language Features Not Supported for Code Generation - this list applies to the (Embedded) MATLAB Function block. Broadly speaking, sparse matrices are not a supported datatype in Simulink, so you cannot output such a signal from the (Embedded) MATLAB Function block. You should probably use the FULL function to convert the sparse matrix to a full matrix before returning it to Simulink. In addition, you may need to pre-allocate 'x' to the expected output size.

More Answers (1)

latsi lab
latsi lab on 25 Jul 2012
think you very match kaustubha govind, finaly i find the solution
i do that:
function y = MelBank(x,n,fs,fl,fh)
eml.extrinsic('myfun');
y = zeros(12,128); % declares the output type for myfun.
y = myfun(x,n,fs,fl,fh);
function y = myfun(x,n,fs,fl,fh)
eml.extrinsic('full');
t = melbankm(x,n,fs,fl,fh);
% Here full takes a sparse input t and returns a
% non-sparse output .
y = full(t);

Categories

Find more on Startup and Shutdown 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!