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

조회 수: 9 (최근 30일)
Sabrine Samorah
Sabrine Samorah 2021년 1월 4일
답변: Rajanya 2024년 12월 19일
function C = fcn(f,U_b)
k = 2*pi*f/U_b;
%Theodorsen fcn C
%besselh is the second kind Hankel fcn
%Declare besselh as extrinsic
coder.extrinsic('besselh');
C = complex(0);
C = besselh(1,2,k)/(besselh(1,2,k)+1i*besselh(0,2,k));
I am using the Matlab fonction block above. I'm using an extrinsic function because 'besselh()' was not supported for code generation. I have defined C as a complex since it's the value that I am expecting it to return (https://fr.mathworks.com/help/simulink/ug/calling-matlab-functions.html#bq1h2z9-47), but I'm still getting this error:
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.
Thank you.

답변 (1개)

Rajanya
Rajanya 2024년 12월 19일
I was able to reproduce the error. The reason for this error is that when you declare a function as ‘extrinsic’, the function is dispatched to MATLAB environment for execution, producing an ‘mxArray’ as the result, and the only supported operations for an ‘mxArray’ are storing it in a variable, passing it to another function or returning it to MATLAB - https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html#:~:text=Define%20the%20local%20function%20returnStringToNumber,mxArrays%20(MATLAB%20Coder).
Here, ‘besselh’ is declared as an ‘extrinsic’ function, so its output is an ‘mxArray’. Hence, the use of ‘besselh’ directly in an arithmetic expression in the following line throws the error.
C = besselh(1,2,k)/(besselh(1,2,k)+1i*besselh(0,2,k));
Thanks! Hope this helps!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by