read
Class:matlab.io.datastore.SimulationDatastore
Package:matlab.io.datastore
Read data in datastore
Syntax
data = read(dst)
[data,info] = read(dst)
Description
returns data from a datastore (data
= read(dst
)matlab.io.datastore.SimulationDatastore
object). Subsequent calls to theread
function continue reading from the endpoint of the previous call. Use theReadSize
property of theSimulationDatastore
object to specify the amount of data, in samples (time steps), to read at a time. Use theprogress
method and theNumSamples
property to determine the current read position.
[
also returns information about the extracted data indata
,info
] = read(dst
)info
.
Input Arguments
dst
—Input datastore
matlab.io.datastore.SimulationDatastore
object
Input datastore, specified as amatlab.io.datastore.SimulationDatastore
object. To create aSimulationDatastore
object, seematlab.io.datastore.SimulationDatastore
.
Output Arguments
data
— Output data
timetable
object
Output data, returned as atimetable
object. For information abouttimetable
, seeTimetables.
info
— Information about read data
structure array
Information about read data, returned as a structure. The structure has one field,FileName
, which is a fully resolved path containing the path string, the name of the file, and the file extension.
例子
Inspect and Analyze Data in Simulation Datastore
This example shows how to log big data from a simulation and inspect and analyze portions of that data by interacting with amatlab.io.datastore.SimulationDatastore
object.
日志大数据模型
Open the example modelsldemo_fuelsys
.
open_system('sldemo_fuelsys')
SelectConfiguration Parameters > Data Import/Export > Log Dataset data to file.
set_param('sldemo_fuelsys','LoggingToFile','on')
Simulate the model.
sim('sldemo_fuelsys')
The MAT-fileout.mat
appears in your current folder. The file contains data for logged signals such asfuel
(which is at the root level of the model).
一个t the command prompt, create aDatasetRef
object that refers to the logging variable by name,sldemo_fuelsys_output
.
DSRef = Simulink.SimulationData.DatasetRef('out.mat','sldemo_fuelsys_output');
Preview Big Data
Use curly braces ({
and}
) to extract the signal elementfuel
, which is the tenth element inDSRef
, as aSimulink.SimulationData.Signal
object that contains aSimulationDatastore
object.
SimDataSig = DSRef{10};
To more easily interact with theSimulationDatastore
object that resides in theValues
property of theSignal
object, store a handle in a variable namedDStore
.
DStore = SimDataSig.Values;
Use thepreview
method to inspect the first five samples of logged data for thefuel
signal.
preview(DStore)
ans = 10x1 timetable Time Data ______________ ______ 0 sec 1.209 0.00056199 sec 1.209 0.0033719 sec 1.209 0.01 sec 1.1729 0.02 sec 1.1409 0.03 sec 1.1124 0.04 sec 1.0873 0.05 sec 1.0652 0.055328 sec 1.0652 0.055328 sec 1.0652
Inspect Specific Sample
Inspect the 603rd sample of loggedfuel
data.
Set theReadSize
property ofDStore
to a number that, considering memory resources, your computer can tolerate. For example, setReadSize
to200
.
DStore.ReadSize = 200;
Read from the datastore three times. Each read operation advances the reading position by 200 samples.
read(DStore); read(DStore); read(DStore);
Now that you are very close to the 603rd sample, setReadSize
to a smaller number. For example, setReadSize
to5
.
DStore.ReadSize = 5;
Read from the datastore again.
read(DStore)
ans = 5x1 timetable Time Data ________ ______ 5.79 sec 1.6097 5.8 sec 1.6136 5.81 sec 1.6003 5.82 sec 1.5904 5.83 sec 1.5832
The third sample of read data is the 603rd sample in the datastore.
Inspect Earlier Sample
Inspect the 403rd sample of loggedfuel
data. Due to previous read operations, the datastore now reads starting from the 606th sample, so you must reset the datastore. Then, you can read from the first sample up to the 403rd sample.
Use the重置
method to resetDStore
.
重置(DStore);
SetReadSize
to200
again.
DStore.ReadSize = 200;
Read from the datastore twice to advance the read position to the 401st sample.
read(DStore); read(DStore);
SetReadSize
to5
again.
DStore.ReadSize = 5;
Read from the datastore.
read(DStore)
ans = 5x1 timetable Time Data ________ _______ 3.85 sec 0.999 3.86 sec 0.99219 3.87 sec 0.98538 3.88 sec 0.97858 3.89 sec 0.97179
Extract Multiple Samples
Extract samples 1001 through 1020 (a total of 20 samples).
Reset the datastore.
重置(DStore)
一个dvance to sample 1001.
DStore.ReadSize = 200;fori = 1:5 read(DStore);end
Prepare to extract 20 samples from the datastore.
DStore.ReadSize = 20;
Extract samples 1001 through 1020. Store the extracted data in a variable namedtargetSamples
.
targetSamples = read(DStore)
targetSamples = 20x1 timetable Time Data ________ ______ 9.7 sec 1.5828 9.71 sec 1.5733 9.72 sec 1.5664 9.73 sec 1.5614 9.74 sec 1.5579 9.75 sec 1.5553 9.76 sec 1.5703 9.77 sec 1.582 9.78 sec 1.5913 9.79 sec 1.5988 9.8 sec 1.605 9.81 sec 1.6101 9.82 sec 1.6145 9.83 sec 1.6184 9.84 sec 1.6049 9.85 sec 1.595 9.86 sec 1.5877 9.87 sec 1.5824 9.88 sec 1.5785 9.89 sec 1.5757
Find Maximum Value of Data in Datastore
Reset the datastore.
重置(DStore)
Write awhile
loop, using thehasdata
method, to incrementally analyze the data in chunks of 200 samples.
DStore.ReadSize = 200; runningMax = [];whilehasdata(DStore) tt = read(DStore); rawChunk = tt.Data; runningMax = max([rawChunk; runningMax]);end
Now, the variablerunningMax
stores the maximum value in the entire datastore.
runningMax
runningMax = 1.6423
Version History
See Also
一个pri esempio
如果dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
一个mericas
- 一个mérica Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)
一个sia Pacific
- 一个ustralia(English)
- India(English)
- New Zealand(English)
- 中国
- 日本(日本語)
- 한국(한국어)