Answer from the Matlab Support facing this issue.
This is a known issue with MAT-file v7.3, which is a current limitation of the HDF5 format. MAT-file v7.3 is based on HDF5, which does not manage freespace as effectively as it should. When a dataset is frequently rewritten or frequently added and deleted as what you were doing in the reproduction code, the file can develop large numbers of holes and grow unnecessarily large. Please refer to the following documentation from the HDF5 group for more information.
https://web.archive.org/web/20150906142926/http://www.hdfgroup.org/HDF5/doc/H5.user/Performance.html
A possible workaround to remove the holes in the file is to load the contents of the MAT-file into workspace and resave them to a MAT-file after you are done rewriting or modifying data in the file.
Another possible workaround is to use the -v7 flag instead, although this removes the functionality of HDF5 to partially load/save variables.
Our development team is also actively working on this issue and I linked your case to an open enhancement request and you will be notified when there is any enhancement existing in a future release regarding this.