Use of Variables in Simulink Matlab Function

조회 수: 5 (최근 30일)
Kilian Lasch
Kilian Lasch 2022년 1월 9일
댓글: Fangjun Jiang 2022년 1월 14일
Hi,
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?
Thanks!

답변 (1개)

Fangjun Jiang
Fangjun Jiang 2022년 1월 10일
In MATLAB Function block Editor, click "Data", define "h" as a parameter.
  댓글 수: 7
Fangjun Jiang
Fangjun Jiang 2022년 1월 14일
If there is no constraint to add input and output to the MATLAB Function block to read and write the value, it certainly makes it easier.
I believe it can store variable size data. Just need to set the proper property values.
Fangjun Jiang
Fangjun Jiang 2022년 1월 14일
Look at the "Example - Incorrect". It is "incorrect" in terms of style guideline but it works in terms of functionality.

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

카테고리

Help CenterFile Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by