Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ExportSimulationData

Exporting(logging)simulationdataprovidesabaselineforanalyzinganddebuggingamodel.Usestandardorcustom
MATLABfunctionstogeneratesimulatedsysteminputsignalsandtograph,analyze,orotherwisepostprocessthe
systemoutputs.

SimulationData
Simulationdatacanincludeanycombinationofsignal,time,output,state,anddatastoreloggingdata.
ExportingsimulationdatainvolvessavingsignalvaluestotheMATLABworkspaceortoaMATfileduringsimulation
forlaterretrievalandpostprocessing.Exportingdataisalsoknownas"datalogging"or"savingsimulationdata."
Youcanhavedataloggedindifferentformats:

Array

Structure

Structurewithtime

MATLABtimeseries

ModelDataLogs
Note:TheModelDataLogsclassissupportedforbackwardscompatibility.StartinginR2016a,youcannotlogdatain
theModelDataLogsformat.SignalloggingusestheDatasetformat.InR2016aorlater,whenyouopenamodelfrom
anearlierreleasethathadusedModelDataLogsformat,themodelsimulatedinuseDatasetformat.

ConsiderconvertingthisdatatotheDatasetformat,whichcansimplifythepostprocessingofdata.Formore
information,seeDatasetConversionforLoggedData.
Youcanalsoimporttheexporteddatatouseasinputforsimulatingamodel.

ApproachesforExportingSignalData
Exportingsimulationdataofteninvolvesexportingsignaldata.Youcanusevariousapproachesforexportingsignal
data.
ExportApproach

Usage

Documentation

ConnectaScopeblockorviewertoa
signal.

IfyouuseaScopeblockforviewing
resultsduringsimulation,consideralso
usingtheScopeblocktoexportdata.

Scope

Saveoutputatasamplerateotherthan
thebasesamplerate.
Scopesstoredataandcanbememory
intensive.
ConnectasignaltoaToFileblock.

ConsiderusingaToFileblockfor
exportinglargeamountsofdata.

ToFile

Saveoutputatasamplerateotherthan
thebasesamplerate.
UsetheMATfileonlyafterthe
simulationhascompleted.
ConnectasignaltoaToWorkspace
block.

Documentinthediagramthe
workspacevariablesusedtostore
signaldata.
Saveoutputatasamplerateotherthan
thebasesamplerate.

ToWorkspace

ConnectasignaltoarootlevelOutport
block.

Considerusingthisapproachfor
loggingdatainatoplevelmodel,ifthe
modelalreadyincludesanOutport
block.

Outport

Setthesignalloggingpropertiesfora
signal.

Usesignalloggingtoavoidadding
blocks.

ExportSignalDataUsingSignal
Logging

Logsignalsbasedonindividualsignal
rates.
Dataisavailableonlywhensimulation
ispausedorcompleted.
Usesignalloggingtologarrayofbuses
signals.
ConfigureSimulink toexporttime,
state,andoutputdata.

Tocapturecompleteinformationabout
thesimulationasawhole,consider
exportingthisdata.
Outputsandstatesareloggedatthe
basesamplerateofthemodel.

DataFormatforLoggedSimulationData
LimitAmountofExportedData
SamplestoExportforVariableStep
Solvers

Logadatastore.

Logadatastoretosharedata
throughoutamodelhierarchy,
capturingtheorderofalldatastore
writes.

LogDataStores

Usethesimcommandtologsimulation
dataprogrammatically.

Usesimtoexporttoonedataobjectthe
time,states,andsignalsimulationdata.

sim

SelecttheReturnassingleobject
parameterwhensimulatingthemodel
usingthesimcommandinsidea
functionoraparforloop.

EnableSimulationDataExport
ToexportthestatesandrootleveloutputportsofamodeltotheMATLABbaseworkspaceduringsimulationofthe
model,useoneoftheseinterfaces:

ConfigurationParameters>DataImport/Exportpane(fordetails,seeDataImport/ExportPane)

simcommand

Inbothapproaches,specify:

Thekindsofsimulationdatathatyouwanttoexport:

Signallogging

Time

Output

Stateorfinalstate

Datastore

Eachkindofsimulationdataexporthasanassociateddefaultvariable.Youcanspecifyyourownvariablesforthe
exporteddata.

Thecharacteristicsoftheloggeddata,including:

DataFormatforLoggedSimulationData

LimitDataLogged

SamplestoExportforVariableStepSolvers

ViewLoggedDataUsingSimulationDataInspector
Toinspectexportedsimulationdatainteractively,considerusingtheSimulationDataInspector.

TheSimulationDataInspectorhassomelimitationsonthekindsofloggeddatathatitdisplays.SeeLimitationsofthe
SimulationDataInspector.

MemoryPerformance
OptimizationforLoggedData
WhenexportingsimulationdatainasimulationmodeotherthanRapidAccelerator,Simulinkoptimizesmemoryusage
inthefollowingsituations.

Whentimestepshappenatregularintervals,Simulinkusescompressedtimerepresentation.Simulinkstoresthe
valueforthefirsttimestamp,thelengthoftheinterval(timestep),andthetotalnumberoftimestamps.

Whenmultiplesignalsuseidenticalsequencesoftimestamps,thesignalsshareasinglestoredtimestamp
sequence.Sharingasinglestoredtimestampcanreducememoryuseforloggeddatabyasmuchasafactorof
two.Anexamplewhenthismemoryperformancecanbeacriticalperformancefactoriswhenloggingbussignals
thathavethousandsofbuselements.

LoggingtoPersistentStorage
Youcanencountermemoryissueswhenyoulogalargenumberofsignalsinalongsimulationthathasmanytime
steps.Loggingtopersistentstoragecanaddressthiskindofmemoryissue.
Tologtopersistentstorage,intheConfigurationParameters>DataImport/Exportpane,selectLogDatasetdata
tofileoption.Specifythekindsoflogging(forexample,signalloggingandstateslogging).

Forloggingoutputandstatesdata,settheFormatparametertoDataset.

IfyouselecttheFinalstatesparameter,cleartheSavecompleteSimStateinfinalstateparameter.

UsingaSimulink.SimlationData.DatasetRefobjecttoaccesssignalloggingandstatesloggingdataloadsdata
intothemodelworkspaceincrementally.Accessingdataforotherkindsofloggingloadsallofthedataatonce.
Fordetails,seeLogDataUsingPersistentStorage.

SeeAlso
Blocks
Outport|Scope|ToFile|ToWorkspace

Functions
sim

RelatedExamples

LogSimulationDataforRoundtripDataLoading

DataFormatforLoggedSimulationData

LimitAmountofExportedData

LogDataUsingPersistentStorage

MoreAbout

OverviewofSignalLoadingTechniques

ComparisonofSignalLoadingTechniques

DataFormatforLoggedSimulationData

SignalDataStorageforLoading

SimulationDataInspector

You might also like