How to create/access and update global variables in Simulink using Data Store Memory block

2 visualizaciones (últimos 30 días)
In the Simulink Model (.slx attached), I would like to create a global variable 'Pulse' which I have attemped doing in the MATLAB function block. I further would like to update this variable such that at each iteration of the simulation, the updated variable is used by the MATLAB function block. I have added the Data Store Memory block to the model, however the model returns the following erroe for the above mentioned steps take:
Simulink cannot determine sizes and/or types of the outputs for block 'globalSimulinkData/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
The variable 'Pulse' is initialised in the MATLAB script as 'PulseInit' (.m file attached).

Respuestas (1)

Deepak Meena
Deepak Meena el 17 de Nov. de 2020
Hi Krupa,
My understanding of your question is that you want to have a variable which change with every time step.So do that you do not a Data Store Memory Block , what you can do is provide a Input array of Pulse along with the time in your simulink model.
Ex : your time steps is 0.1 so , our time array will be
t = [0:0.1:3]';
similarly let's assume our pulse be random(for example , we can any have values ):
pulse = rand(1,31)';%%size of both arrays should be same
Now to connect these inputs to simulink , go to Modelling->Model settings->Data Import/Export.
You would se ethis expression [t u], here t stands for our time array and replace u with pulse and apply the settings .
Now use the Input port block in simulink and connect this to your Function block.
More more details refer to this doc : Import from Workspace
Thanks
Deepak

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by