Symbolic variable in matlab function block

5 visualizaciones (últimos 30 días)
Mukesh Choudhary
Mukesh Choudhary el 23 de Feb. de 2023
Respondida: Govind KM el 17 de Oct. de 2024
I created a function [y1,y2,y3]=example(x1,x2,x3) where it solves a list of equation using symbolic toolbox (syms and solve). Then i evaluated the expression to get values (eval command). The output of the function is this evaluated value. This works well when i call it from command window.
I want to call this function in simulink matlab function block. I tried but it gave an error regarding coder.extrinsic. I used this command on the top in my matlab function block (coder.extrinsic('example')). It gave an 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.''
I tried to initialize y1,y2,y3 as double (0) just before the function call in block.
Now it gives a new error '
  • Size mismatch for MATLAB expression 'Fxr1_l'. Expected = 1x1 Actual = 0x0
'
I dont understand as the function output y1,y2,y3 should be single value.
Has someone faced similiar problem?

Respuestas (1)

Govind KM
Govind KM el 17 de Oct. de 2024
Hi Mukesh,
I was facing a similar issue when I was using symbolic expressions inside a MATLAB Function block. A workaround for me was to directly generate a MATLAB function block from my symbolic expression using matlabFunctionBlock. More information can be found in the documentation below:
In case you can performing code generation, a reason for the mentioned error is incompatible array sizes or unsupported implicit expansion. A workaround is mentioned in the following MATLAB Answers post:
Hope this helps!

Community Treasure Hunt

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

Start Hunting!

Translated by