Use of Variables in Simulink Matlab Function

3 views (last 30 days)
Kilian Lasch
Kilian Lasch on 9 Jan 2022
Commented: Fangjun Jiang on 14 Jan 2022
I'd like run a complex code in a Matlab Function Block in Simulink. The initialization of some variables via another matlab script works fine, so some objects (e.g. the double h =1 ) the are loaded to the Model Workspace. (they appear in Model Explorer)
When running the Simulink Model including the Matlab Function Block, h is unknown.
function y = fcn(u)
y = u *h;
Error: Undefined function or variable 'h'. Function 'MATLAB Function1' (#66.156.157), line 6, column 8: "h"
How to read and write Variables from Model Workspace in the Matlab Function Block?

Answers (1)

Fangjun Jiang
Fangjun Jiang on 10 Jan 2022
In MATLAB Function block Editor, click "Data", define "h" as a parameter.
Fangjun Jiang
Fangjun Jiang on 14 Jan 2022
Look at the "Example - Incorrect". It is "incorrect" in terms of style guideline but it works in terms of functionality.

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!