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

조회 수: 80 (최근 30일)
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
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 2월 9일
Which line is the problem occurring on? If it is that last line, could you try breaking it up into an assignment to a temporary variable and then on the (new) next line, assign the temporary to "found" ? I am thinking the problem might have to do with the "loc" rather than the "found".
Will Forfang
Will Forfang 2013년 2월 9일
편집: Will Forfang 2013년 2월 9일
Yes, it's the last line. Do you mean like this?
coder.extrinsic('findpeaks');
[pks, loc] = findpeaks(xcn1,'MINPEAKHEIGHT',.4,'MINPEAKDISTANCE',30);
temp = loc.*(Fs/length(signal)); %multiply index by Fs/N to get frequency
found= temp;
It still outputs the same error. Here's the full error report:
Expected either a logical, char, int, fi, single, or double. Found an mxArray. MxArrays are returned from calls to the MATLAB interpreter and are not supported inside expressions. They may only be used on the right-hand side of assignments and as arguments to extrinsic functions.
Function 'Subsystem1/Algorithm/MATLAB Function' (#76.609.612), line 16, column 8:
"*loc*"
Launch diagnostic report.
I've also tried it this way, and yielded the same error:
temp = loc; %multiply index by Fs/N to get frequency
found= temp.*(Fs/length(signal));
Thanks for your reply,
-Will

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 9일
  댓글 수: 4

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by