Saving data at the end of a simulation to use it at the beginning of another simulation

24 Ansichten (letzte 30 Tage)
I am trying to save in a SIMULINK variable (not workspace) the last data showed in a Display block (as Limit data point to last) in a first simulation, and then run a second simulation that uses that value.
To do this I have written the following code in InitFcn (callback function), in Model properties. Tha value I want to save in the first run is "Prueba_no_modules_out", so I was thinking to structure the code as follows: while this variable does not exist in Simulink, I use a inicialization value (%1). In the second run, the input variable (Prueba_no_modules) uses the last simulation data output (%2), because "Prueba_no_modules_out" already would exist.
code in InitFcn:
if ~exist('Prueba_no_modules_out')
Prueba_no_modules = 4; %1
else
Prueba_no_modules = Prueba_no_modules_out; %2
end
My problem comes out when trying to save "Prueba_no_modules_out" as a variable in SIMULINK to use it in InitFCN. "Prueba_no_modules" works propertly (it is a variable in a constant block).
But I tried to generate the variable "Prueba_no_modules_out" using "To workspace", and although it does generates it in workspace, InitFcn does not recognizes it as "out.Prueba_no_modules_out" neither as just "Prueba_no_modules_out".
I have found this post where it speaks about "SimState" https://es.mathworks.com/matlabcentral/answers/181663-how-to-save-the-last-value-of-a-simulation-in-a-mat but I do not really understand it...
Hope I explained well.
Thank you
- Ester

Akzeptierte Antwort

Fangjun Jiang
Fangjun Jiang am 3 Jun. 2020
Ctrl+E to open configuration parameters, Data Import/Export, un-check "Single simulation out" will save the "To Workspace" to "Prueba_no_modules_out", not "out.Prueba_no_modules_out"
  5 Kommentare
Fangjun Jiang
Fangjun Jiang am 4 Jun. 2020
The common method is to save other variables using "To Workspace" block, save it to array and then run xlswrite() in post processing. "Single simulation out" just combines all saved variables into one structure.
Ester Panea Murillo
Ester Panea Murillo am 4 Jun. 2020
Thank you very much Fangjun for your fast responses, everithing works!!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by