The simplest solution to write out the data is to simply use a smaller batch size to begin with. Matlab’s memory footprint grows with every cycle, so smaller batch sizes will have less “overhead” memory usage, and this will also minimize the lost cycles if an error does occur. However I would expect that any lost cycle would make you want to fix it, no? See Help->General Help -> MemoryAndSpeed for general memory minimization tips.
But your third question implies that you want to save the data from the cycles that errors, right up to the module it errors on? I wouldn’t trust the data from that cycle, since it ran out of memory and who knows what happened to the handles structure at that point.
It seems to me that writing intermediate results would have a higher cost overall (slowing down batches that don’t error because they have to access the disk more) than the benfit gained.