how to save a file in ".m" format using command
5 次查看(过去 30 天)
显示 更早的评论
I need to save some values in .m format. when I save the values in .mat format and load it and do calculation, the results are not correct.
s1=load ('ppvalue.mat');
mu1=mean(s1);
c1=s1(1,1); % value=8
b1=mu1(1,1); % value=36.6678
d1=c1-b1; %it gives me 0 (instead of negative value)
0 个评论
回答(1 个)
Brian B
2013-2-8
编辑:Brian B
2013-2-8
You should not save data in an m-file; a mat-file is the best way. I believe the problem is how you are loading the data. If you call
load('ppvalue.mat')
the variables saved in the file are created in the current workspace with their values as they were saved in the file. If, instead, you assign the output of the call to load to a variable as in
s1 = load('ppvalue.mat');
then s1 will be a scalar structure with one field for each variable saved in the mat-file. The field names will be the names of the original variables.
Your code above attempts to compute the mean of the struct s1, which is not defined. Instead, try
mu1 = mean(s1.varname)
where varname is the original name of the variable that was saved to the mat-file. To see what it is, just look at s1 in the command window.
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!