Calling a Function in Matlab function block in Simulink.

조회 수: 5 (최근 30일)
Prateek Tiwari
Prateek Tiwari 2020년 6월 30일
댓글: VIGNESH BALAJI 2023년 10월 31일
Hello,
I want to call a function from a defined directory inside a matlab function block. I know that it can be done using 'coder.extrinsic () '. However I still get error as below
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 arg
I know this can be solved by intitializing the variables, however in my case finding a required size is difficult and I do not know how else can I solve this, Is there anyway to intialize without defining a specific dimension of the variable?. I have also attached a picture of my function, please find below.
  댓글 수: 1
VIGNESH BALAJI
VIGNESH BALAJI 2023년 10월 31일
Did you face any problems while calling user defined functions inside matlab function block ? I faced this issue. If you have figured out a way, let me know

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

답변 (1개)

Vidhathri LNU
Vidhathri LNU 2020년 7월 3일
You can declare those variables as variable sized with an upper bound on the size. That should solve the issue
function y = myfun(x)
coder.varsize('y', [1024 2]); %x must never exceed 1024
coder.extrinsic('fun');
y = zeros(x, 2); %pre-declare the type and size of y
y = fun(x);
Refer to the documentation here for more details on using coder.varsize.
  댓글 수: 1
Prateek Tiwari
Prateek Tiwari 2020년 7월 3일
Thank you for your response.
I already tries using coder.varsize(). In simulink it says this call back is not supoorted (MATLAB 2019B).

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

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by