I'm writing an agent-based simulation in MATLAB in which agents play a game in rounds, selling stuff to each other. Pretty much everything (agents, items, locations, contracts...) is implemented as an object using MATLAB's OOP functionalities.

**Every round I want to take a snapshot of my simulation and store it on disk** so I can analyze later how the simulation developed. Now my question is what would be the **best way to do so?**

**My current idea** is that the main loop calls on every agent and asks it to report its status (e.g. how many items of what property do you own, what are your contractual obligations, account balance... While if necessary the agents call on objects they own and ask for their status and include that information in their report). My idea was to make the **agents' reports a string, possibly in XML form. Then add all reports together with a time stamp and add it at the end of a text file**.

But since I have never done anything like this I'm not sure if this is a good approach. **My main concern** apart from having the data in a format that I can easily analyze later on, is the **speed** of creating the snapshot and writing it to disk. As my simulation is pretty large I expect a lot of data to be stored each round.

**Alternative ideas** are:

1. Storing everything in a **data base**. But I assume database access is rather slow compared to a text file. And since the number of objects owned by each agent can change, I'm not too sure about the data base structure either.
2. Using **.mat files**. But I don't know if they are easily extendable and how they would deal with a changing structure (i.e. agents owning different items per round)

Thanks for any comments and suggestions!