Is there a way to remove or rename a variable in a big MAT file?
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ray Lee
el 14 de Dic. de 2017
I want to rename/remove a variable in very large MAT file but want to avoid load all the data, modify variables and write all new data to the disk.
The MAT file is hundreds GB and load/write all leads to a heavy IO load.
5 comentarios
Stephen23
el 15 de Dic. de 2017
Editada: Stephen23
el 15 de Dic. de 2017
@Ray Lee: fair enough.
As an alternative it may be possible to process the fieldnames using some regular expressions (or something similar) to allow for some variation in the names, at the point when the data is being loaded. This would then allow the file to remain unchanged.
Walter Roberson
el 15 de Dic. de 2017
I find hints in the HDF5 documentation that renaming in-place might be possible -- but that might perhaps only apply to files constructed a particular way. -v7.3 MAT files are "modified" HDF5 format.
Respuesta aceptada
OCDER
el 15 de Dic. de 2017
Editada: OCDER
el 15 de Dic. de 2017
You can use MEX code to delete a variable from a .mat file, but then you still have to save the variable via -append feature. The mex code (RemoveVariableFromMatFile) was provided in the Q&A https://www.mathworks.com/matlabcentral/answers/254048-how-can-i-delete-variables-in-my-mat-file-without-loading-them-into-matlab-7-2-r2006a
You have to compile the MEX code using a C compiler https://www.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c++-compiler
mex RemoveVariableFromMatFile.c
Then you do this:
T = load('filename.mat', 'BadVarName');
GoodVarName = T.('BadVarName')
RemoveVariableFromMatFile('filename.mat', 'BadVarName');
save('filename.mat', 'GoodVarName', '-append')
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre 工作区变量和 MAT 文件 en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!