How to create an array in Simulink to save data and process these data in Simulink

174 vues (au cours des 30 derniers jours)
Dear all,
I want to create an array in Simulink to save the satified data and then deal with these data in Simulink. For example, there is a system made by a'step function' and a sine wave with 100 Hz frequency. The sampling frequency of this system is 1 kHz. Now, assumeing a rising edge from the step function at 0.1 s, how to capture and save the one cycle data ( the circled part in the following figure) in Simulink? Moreover, if I want to do some online calculation in Simulink with the saved data, can I use the 'MATLAB function' block as what we did in the MATLAB?
Thank you for your help.
Di

Réponses (2)

Rhea Chandy
Rhea Chandy le 5 Jan 2021
Hi!
You can save data from Simulink to a MAT-file using the To File block. To save it as an array, specify the Save format parameter as Array. Further, you can specify the sample period and offset at which to collect data points using the Sample time parameter.
You can also consider writing the input signal data to a workspace using the To Workspace block, however the data will not be available until the simulation pauses or stops.

Tamir Suliman
Tamir Suliman le 24 Jan 2023
you can use the "To Workspace" block to save data to a variable in the MATLAB workspace. You can then use the "From Workspace" block to bring the data back into a Simulink model for further processing.
  1. To save data to an array, place a "To Workspace" block in your model.
  2. In the block's parameters, specify the variable name you want to use for the array (e.g. "myArray") and the "Save format" (e.g. "Array").
  3. Connect the signal you want to save to the input of the "To Workspace" block.
  4. To bring the data back into the model, place a "From Workspace" block in your model.
  5. In the block's parameters, specify the same variable name you used in step 2 (e.g. "myArray").
  6. Connect the output of the "From Workspace" block to the input of the block where you want to process the data.
Then you can use standard simulink block to process these data.

Community Treasure Hunt

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

Start Hunting!

Translated by