Initialize Global Variable in Simulink

조회 수: 11 (최근 30일)
MB
MB 2022년 3월 29일
댓글: VIGNESH BALAJI 2023년 10월 27일
Getting the following error in Simulink: "Global declaration not resolved to a Data Store Memory block registered via the Ports and Data Manager."
Background: I am trying to run simple code inside a Matlab function block and require a variable GEAR initialized to 1 only at the beginning of the simulation so the Function Block code can increment/decrement GEAR. I have tried declaring the variable as "global GEAR" and then "GEAR = 1" in Callbacks - InitFcn, as well as placing in a .mat file but but get the error above when the variable GEAR is used within the Matlab Function Block.
I have not been successful (even with Matlap documentation) to use the Data Store. And more to the point think there must be an easier way to do such a basic thing as initialize a global variable than start creating data stores. And what/where is the "Ports and Data Manager" - it doesn't even come up in the help file seach.
Any help appreciated.

채택된 답변

Fangjun Jiang
Fangjun Jiang 2022년 3월 29일
In your MATLAB Function block editor, click "Edit Data" icon on the tool strip, add "Gear" as a data.
In the Simulink model, add a "Data Store Memory" block and name the "data store name" as "Gear". Resolve any error by setting property values.
see this link
  댓글 수: 4
MB
MB 2022년 3월 29일
Just for anyone else stumbling across this thread needing help... The Ports & Data Manager in the tool strip appears while editing the Matlab Function Block - at least in 2021b. You can then add a data as previous answer guided, but be sure to changed Scope in the table to Data Store Memory because it defaults to another Input. Then continue as previous answer guided by adding a Data Store, changing name and resolving the errors given.
Thank you sir.
VIGNESH BALAJI
VIGNESH BALAJI 2023년 10월 27일
Where does the Ports & Data Manager appear ? Can you please share me a screenshot. I am unable to find it.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Gears에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by