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

7 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

goerk
goerk il 20 Mar 2017
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 Commento
Christian Stier
Christian Stier il 21 Mar 2017
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.

Accedi per commentare.

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by