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

9 vues (au cours des 30 derniers jours)
Sabrine Samorah
Sabrine Samorah le 4 Jan 2021
Réponse apportée : Rajanya le 19 Déc 2024
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.

Réponses (1)

Rajanya
Rajanya le 19 Déc 2024
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!

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by