how to save a file in ".m" format using command
조회 수: 9 (최근 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!