store
Store data in the internal memory of a (file or monitor) logger object
Since R2022b
Description
Examples
Log Data to Disk in a Custom Training Loop
This example shows how to log data to disk when training an agent using a custom training loop.
Create a FileLogger
object using rlDataLogger
.
flgr = rlDataLogger();
Set up the logger object. This operation initializes the object performing setup tasks such as, for example, creating the directory to save the data files.
setup(flgr);
Within a custom training loop, you can now store data to the logger object memory and write data to file.
For this example, store random numbers to the file logger object, grouping them in the variables Context1
and Context2
. When you issue a write command, a MAT-file corresponding to an iteration and containing both variables is saved with the name specified in flgr.LoggingOptions.FileNameRule
, in the folder specified by flgr.LoggingOptions.LoggingDirectory
.
for iter = 1:10 % Store three random numbers in memory % as elements of the variable "Context1" for ct = 1:3 store(flgr, "Context1", rand, iter); end % Store a random number in memory % as the variable "Context2" store(flgr, "Context2", rand, iter); % Write data to file every 4 iterations if mod(iter,4)==0 write(flgr); end end
Clean up the logger object. This operation performs clean up tasks like for example writing to file any data still in memory.
cleanup(flgr);
Input Arguments
lgr
— Date logger object
FileLogger
object | MonitorLogger
object | ...
Data logger object, specified as either a FileLogger
or a
MonitorLogger
object.
context
— Name of the saved variable
string
| char
vector | ...
Name of the saved variable, specified as either a string or character vector. All
data associated with iteration iter
and the name
context
is vertically concatenated in a single MATLAB® variable named context
. This variable is then written
to the logger target (either a MAT-file or a trainingProgressMonitor
object) when write
is invoked
for lgr
.
data
— Data to be saved
any fundamental MATLAB datatype | ...
Data to be saved, specified as any fundamental MATLAB datatype. Data associated with the same iteration and the same context name is grouped in a single variable.
iter
— Iteration number
positive integer | ...
Iteration number, specified as a positive integer. When store
is executed multiple times with the same iteration number, data is appended to the
memory entry for that iteration. This memory entry, which can contain several context
variables, is then written to the logger target as a single unit (for example as a
single MAT-file) when write
is invoked for
lgr
.
Version History
Introduced in R2022b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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.
Americas
- Amé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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)