How to load, update and save data neatly
15 次查看(过去 30 天)
显示 更早的评论
I have a variable saved to a .mat file which I wish to load in, update (extend) and save out again to the same file.
Obviously I can just call load with no output argument and then save. But people generally seem to say that
s = load( someFilename );
is far better than using the no output argument form. This I understand.
What I am finding difficult to do neatly is the saving back of my updated data. I can update easily as:
s.myVar = someFunction( s.myVar );
but then I can't just do:
save( someFilename, 's' )
as that will leave me with a structure in my file which would not then match the original format. I also can't do:
save( someFilename, 's.myVar' )
as this is clearly nonsense.
So do I really have to do the following?:
myVar = s.myVar;
save( someFilename, 'myVar' )
If so this seems to obviate the purpose of calling load with an output argument in the first place.
0 个评论
采纳的回答
Star Strider
2014-9-3
See if the matfile function does what you want. (I’m not certain when it was introduced, but it’s in R2014a.)
3 个评论
Star Strider
2014-9-3
Yes, according to the documentation, it doesn’t support user-defined classes. Sorry.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!