Need help saving an array into a variable and using that variable during the same simulation.

Hello,
So I am trying to register a specific number or array during a simulation and assign it to a variable which I can use during the same simulation. Using the TO WORKSPACE does not help my problem as the data will be saved and can be used in the next simulation when the current simulation is stoped. It would be great if someone can help me with that. what are my options ? would s function help?

Answers (1)

Put it into a signal that you attach as needed, or register global data. https://www.mathworks.com/help/simulink/ug/using-global-data-with-the-matlab-function-block.html

4 Comments

I have tried the process you mentioned. However, after storing the integer in the data store memory as A. I cannot use that A anywhere, an error shows that A is not defined. And if I Syms A, the value of A still does not change. I have used data store read to make sure the value is there and it is. The question is how to use that A in my data store memory.
Syms ? As in the Symbolic Toolbox? It is difficult to use the symbolic toolbox with Simulink.
I mean when I use the variable that I have stored in the data memory lets say Its called A. If I use this A anywhere lets say in the frequency of a PWM generator block. I get an error that A is not defined
Is this intended to be something that varies with time? Or is it something that you calculate once and then remains unchanged until the end of the simulation? If it is calculated once then can it be calculated at initialization time?

This question is closed.

Asked:

on 8 Mar 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!