Syntax Error using Fcn Block
5 views (last 30 days)
Show older comments
I have been trying to use Fcn Block in simulink but i get the error
The expression: (d1*h11)*(u(7))-(d1*h12+d1*C1)*(u(2))+(d2*h7+d2*h8+d3*h10)*(u(3))-(d2*C2+d3*C3)*(u(4))-d3*C3*(u(6))+d3*h10*(u(5))
in 'slx_drips/DRIPS/Fcn1'
has a syntax error
Please can somebody solve this error.
Thanks

0 Comments
Answers (1)
sanidhyak
on 11 May 2025
I understand that you are encountering a syntax error in the “Fcn” block of Simulink when trying to use an expression that includes variables such as “d1”, “h11”, “C1”, etc. This issue arises because Simulink’s “Fcn” block does not support named variables—it only permits operations involving constants and the input vector “u(i)”.
To resolve this issue, I recommend either precomputing the constants or switching to a “MATLAB Function" block, which supports named variables. Please refer to the following approach using a “MATLAB Function" block:
function y = customFcn(u)
% Define constants
d1 = ...; h11 = ...; h12 = ...; C1 = ...;
d2 = ...; h7 = ...; h8 = ...; C2 = ...;
d3 = ...; h10 = ...; C3 = ...;
% Compute expression
y = (d1*h11)*u(7) - (d1*h12 + d1*C1)*u(2) + ...
(d2*h7 + d2*h8 + d3*h10)*u(3) - ...
(d2*C2 + d3*C3)*u(4) - d3*C3*u(6) + d3*h10*u(5);
end
You can insert this block by navigating to “Simulink Library > User-Defined Functions > MATLAB Function” and double-clicking it to edit the code.
Alternatively, if you still wish to use the “Fcn" block, you must precompute all variables like “d1*h11”, etc., externally (in MATLAB workspace or Constant blocks), and only use those scalar values in the block.
For more information on how the “Fcn” block works, you may refer to the official documentation:
I hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!