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 Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by