How can I programmatically register Data Stores for the Matlab Function block, i.e. without using the Ports and Data manager?

4 次查看(过去 30 天)
I want to script a Matlab Function (Matlab Function Block in Simulink) for routing model values to global variables, which are linked to memory spaces on a realtime platform after code generation. The routing is defined in an external table, the routing within the model should be generated automatically via script.
The routing with the Matlab Function block works fine, the only step, which I couldn't do programmatically, is registering the global variable / the Data Store to the Matlab Function block. Manually this is done via the Ports and Data Manager.

回答(1 个)

goerk
goerk 2017-3-20
I had a similar problem and the following solution worked for me (Matalb 2016b). Example Matlab function with the Name 'MyMatlabFcn':
function MyMatalbFcn(u)
global ADwinDATA_1
ADwinDATA_1 = u;
end
Code to add the global data to the Function:
% Code to programmaticaly add a Stateflow.Data Object
s = slroot;
c = s.find('-isa','Stateflow.EMChart','-and','Name','MyMatlabFcn');
data_new = Stateflow.Data(c);
data_new.Name = 'ADwinDATA_1';
data_new.Scope = 'Data Store Memory';
  1 个评论
Christian Stier
Christian Stier 2017-3-21
Many thanks, that works for me, too.
However I am wondering, if there is any solution, that works without the Stateflow toolbox, as the MatlabFcn block is a standard simulink block.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by