MATLAB: Error: “Expected either a logical, char, int, fi, single, or double. Found an mxArray.”

matlab codermxarraysimulinksimulink coder

I have a "Matlab Function" block in simulink containing the following code:
function found = FFTscan( signal, Fs )
PSD=real(fft(signal,2^nextpow2(length(signal)))); %est. power spec density
PSDn=PSD./max(PSD); %normalizes values from FFT
framen=[.0007 .0642 1 .394 .0063]; %frame for XCORR
xcn=xcorr(PSDn,framen); %xcorrelates normalized FFT w/ frame
xcn1 = xcn(((length(xcn)-1)/2):end); %turns 2sided xcorr into 1sided
coder.extrinsic('findpeaks');
[pks, loc] = findpeaks(xcn1,'MINPEAKHEIGHT',.4,'MINPEAKDISTANCE',30);
found=loc.*(Fs/length(signal)); %multiply index by Fs/N to get frequency
The purpose is to take a frame of an incoming signal in the time domain, transform it to the freq domain, then cross-correlate it with a frame of a known signal. This function works fine if I run it in the matlab workspace, but if I try to use it in a simulink model it throws the error mentioned in the title.
How can I use the data in "loc" as output for my simulink block?
Thanks,
-Will
Related Question