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. This example is meant as a demonstration and does not log big data.
Log Big Data from Model
Open the model ThreeSigs.
To log data to persistent storage, select Configuration Parameters > Data Import/Export > Log data to file. Alternatively, you can log data in Dataset format to a MAT file instead of the workspace programmatically.
Set the stop time of the simulation to 3000 seconds and simulate the model.
The MAT file out.mat appears in your current folder. The software stores logged output data in the MAT file with the variable name yout.
Create a DatasetRef object that refers to the logged signal data.
Preview Big Data
To return a SimulationDatastore representation of the sineSig signal, which is the first element in the DatasetRef object DSRef, use curly braces. The SimulationDatastore object exists in the Values property of the returned Signal object.
To inspect the first ten samples of logged sineSig data, use preview.
ans = 10×1 timetable
Time Data
_______ ________
0 sec 0
0.1 sec 0.099833
0.2 sec 0.19867
0.3 sec 0.29552
0.4 sec 0.38942
0.5 sec 0.47943
0.6 sec 0.56464
0.7 sec 0.64422
0.8 sec 0.71736
0.9 sec 0.78333
Inspect Specific Sample
Suppose you want to inspect the 603rd sample of logged sineSig 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
________ ________
60 sec -0.30481
60.1 sec -0.39837
60.2 sec -0.48795
60.3 sec -0.57265
60.4 sec -0.65164
Inspect Earlier Sample
To inspect an earlier sample, reset the datastore to start reading from the first sample. For example, inspect the 403rd sample of logged sinSig data. Due to previous read operations, the datastore now reads starting from the 606th sample.
To read DStore from the beginning, use reset. Then, set ReadSize to 200 and 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
________ _______
40 sec 0.74511
40.1 sec 0.67481
40.2 sec 0.59776
40.3 sec 0.51474
40.4 sec 0.42658
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
_________ ________
100 sec -0.50637
100.1 sec -0.41775
100.2 sec -0.32496
100.3 sec -0.22892
100.4 sec -0.13059
100.5 sec -0.03096
100.6 sec 0.06898
100.7 sec 0.16823
100.8 sec 0.2658
100.9 sec 0.36072
101 sec 0.45203
101.1 sec 0.53882
101.2 sec 0.62023
101.3 sec 0.69544
101.4 sec 0.76371
101.5 sec 0.82434
⋮
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.