You can log big data from a simulation and inspect and analyze portions of that data by interacting with a matlab.io.datastore.SimulationDatastore object.
Log Big Data from Model
Open the model sldemo_fuelsys.
Select Configuration Parameters > Data Import/Export > Log Dataset data to file to log data to persistent storage. Alternatively, you can log data using Dataset format to a MAT file instead of the workspace programmatically.
Simulate the model.
The MAT file out.mat appears in your current folder. Logged signal data is stored in the MAT file with the variable name sldemo_fuelsys_out.
Create a DatasetRef object that refers to the logged signal data.
Preview Big Data
Use curly braces to return a SimulationDatastore representation of the fuel signal, which is the tenth element in the DatasetRef object DSRef. The SimulationDatastore object exists in the Values property of the returned Signal object.
Use the preview function to inspect the first ten samples of logged data for the fuel signal.
ans=10×1 timetable
Time Data
______________ ______
0 sec 1.2855
0.00056195 sec 1.2855
0.0033717 sec 1.2855
0.01 sec 1.2398
0.02 sec 1.199
0.03 sec 1.1628
0.04 sec 1.1309
0.043098 sec 1.1309
0.043098 sec 1.1309
0.043098 sec 1.1309
Inspect Specific Sample
Suppose you want to inspect the 603rd sample of logged fuel data. Set the ReadSize property of DStore to a number that, considering memory resources, your computer can tolerate. For example, set ReadSize to 200.
Read from the datastore three times. Each read operation advances the reading position by 200 samples.
Now that you are close to the 603rd sample, you can set ReadSize to a smaller number to make the target sample easier to find. For example, set ReadSize to 5.
Read from the datastore again. The third sample of read data is the 603rd sample in the datastore.
ans=5×1 timetable
Time Data
________ ______
5.83 sec 1.6609
5.84 sec 1.6733
5.85 sec 1.6831
5.86 sec 1.691
5.87 sec 1.6975
Inspect Earlier Sample
You can also inspect an earlier sample. For example, inspect the 403rd sample of logged fuel data. Due to previous read operations, the datastore now reads starting from the 606th sample.
Use the reset function to reset DStore. Then, read from the first sample up to the 403rd sample.
Set ReadSize to 200.
Read from the datastore twice to advance the read position to the 401st sample.
Set ReadSize to 5 and read from the datastore. Now, the third sample of read data is the 403rd sample in the datastore.
ans=5×1 timetable
Time Data
________ _______
3.86 sec 0.9895
3.87 sec 0.98253
3.88 sec 0.97559
3.89 sec 0.96867
3.9 sec 0.96178
Extract Multiple Samples
You can also use the read function to extract multiple samples. For example, extract samples 1001 through 1020.
Reset the datastore. Then, advance to sample 1001 by setting the ReadSize property to 200 and reading the datastore five times.
Set the ReadSize to 20 to extract 20 samples from the datastore.
Extract samples 1001 through 1020. Store the extracted data in a variable named targetSamples.
targetSamples=20×1 timetable
Time Data
________ ______
9.77 sec 1.68
9.78 sec 1.6856
9.79 sec 1.6905
9.8 sec 1.6948
9.81 sec 1.6812
9.82 sec 1.6714
9.83 sec 1.6642
9.84 sec 1.659
9.85 sec 1.6553
9.86 sec 1.6527
9.87 sec 1.6684
9.88 sec 1.6806
9.89 sec 1.6904
9.9 sec 1.6982
9.91 sec 1.7047
9.92 sec 1.7101
⋮
Find Maximum Value of Data in Datastore
Use the hasdata function as the condition for a while loop to incrementally analyze the data in chunks of 200 samples.
The variable runningMax stores the maximum value in the entire datastore.