How do I save structured objects into mat-files?
1 次查看(过去 30 天)
显示 更早的评论
I am dealing with large object in my research. I am not familiar with class oriented programing in MATLAB. However, I wanted to save the object into Mat-files. I tried two following ways. But neither way works out with separate message:
objMain.obj1 = function1(Variables);
objMain.obj2 = function1(Variables);
objMain.obj3 = function1(Variables);
objMain.obj4 = function1(Variables);
dir2Save = 'C:\Documents\Matlab\Research';
fname = ['mainTask' int2str(1)];
save([dir2Save '\' fname '.mat'], objMain);
*Message:* _Error using save
_Argument must contain a string._
save([dir2Save '\' fname '.mat'], '-struct', objMain);
*Message:* _Error using save
The argument to -STRUCT must be the name of a scalar structure variable._
Does any body have any ideas how to solve....
Thanks for your help.
Mahesh
1 个评论
Stephen23
2016-7-31
@Mahesh: I fixed your incorrect terminology: an M-file is a script or function, a mat file is a binary file used to store data.
采纳的回答
the cyclist
2016-7-30
编辑:the cyclist
2016-7-30
Try
save([dir2Save '\' fname '.mat'], 'objMain')
You needed to enclose the variable name in quotes, as the second argument.
5 个评论
更多回答(0 个)
另请参阅
类别
在 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!