Main Content

reset

Class:matlab.io.datastore.sdidatastore
Package:matlab.io.datastore

Reset the read position

Syntax

sdi_ds.reset

Description

sdi_ds.resetresets the read position for thematlab.io.datastore.sdidatastore,sdi_ds, to the beginning.

Examples

expand all

Amatlab.io.datastore.sdidatastorereferences signal data in the Simulation Data Inspector repository. When the signal is too large to fit into memory, you can use thematlab.io.datastore.sdidatastoreto incrementally process the data manually or to create a tall timetable for the signal that handles the incremental processing for you. This example shows how to process data using amatlab.io.datastore.sdidatastore.

创建一个matlab.io.datastore.sdidatastorefor a Signal

Simulate thesldemo_fuelsysmodel, which is configured to log several signals, to create data in the Simulation Data Inspector repository.

sim卡('sldemo_fuelsys')

Use the Simulation Data Inspector programmatic interface to get the signal ID for the signal.

runCount = Simulink.sdi.getRunCount; latestRunID = Simulink.sdi.getRunIDByIndex(runCount); latestRun = Simulink.sdi.getRun(latestRunID); speedSigID = latestRun.getSignalIDByIndex(4);

Use the signal ID to create amatlab.io.datastore.sdidatastorefor thespeedsignal.

speedSDIds = matlab.io.datastore.sdidatastore(speedSigID);

Verify the Contents of the Datastore

Check theNameproperty of thematlab.io.datastore.sdidatastoreto verify that it matches your expectations.

speedSDIds.Name
ans = 'map'

You can also use thepreviewmethod to check that the first ten samples in the signal look correct.

speedSDIds.preview
ans=10×1 timetableTime Data ______________ _______ 0 sec 0.589 0.00056199 sec 0.58772 0.0033719 sec 0.58148 0.01 sec 0.56765 0.02 sec 0.54897 0.03 sec 0.53264 0.04 sec 0.51837 0.05 sec 0.50594 0.055328 sec 0.5 0.055328 sec 0.5

Process Signal Data with thematlab.io.datastore.sdidatastore

When your signal is too large to fit into memory, you can use thereadDatamethod to read chunks of data from the Simulation Data Inspector repository to incrementally process your data. Use thehasdatamethod as the condition for a while loop to incrementally process the whole signal. For example, find the maximum signal value.

latestMax = [];whilespeedSDIds.hasdata speedChunk = speedSDIds.read; speedChunkData = speedChunk.Data; latestMax = max([speedChunkData; latestMax]);endlatestMax
latestMax = 0.8897

On each read operation, thereadmethod updates the read position for the start of the next read operation. After reading some or all of thematlab.io.datastore.sdidatastore, you can reset the read position to start again from the beginning of the signal.

speedSDIds.reset

Process Signal Data in Memory

When the signal referenced by yourmatlab.io.datastore.sdidatastorefits into memory, you can use thereadall方法阅读所有的信号数据到内存中processing, rather than reading and processing the data incrementally with thereadmethod. Thereadallmethod returns atimetablewith all the signal data.

speedTimetable = speedSDIds.readall; speedMax = max(speedTimetable.Data)
speedMax = 0.8897

版本历史

Introduced in R2017b