Symbolic variable in matlab function block
Show older comments
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?
Answers (1)
Govind KM
on 17 Oct 2024
0 votes
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!
Categories
Find more on MATLAB Function Block Basics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!