Dear matlab users after I write m file script and run ,it work correctly but when I try open for additional work ,I got different characters .How can open it ? Thank you.

조회 수: 1 (최근 30일)
Dear MATLAB users after I write m file script and run ,it work correctly but when I try open for additional work ,I got different characters .How can open it ? Thank you.
  댓글 수: 3
Kelil Mohammed
Kelil Mohammed 2018년 8월 18일
Thank you very much for your response. When I open the file I got this at the first line. except this line the other lines corrupted and unreadable characters appear. 'MATLAB 5.0 MAT-file, Platform: PCWIN64, Created on: Sun Aug 12 22:34:26 2018 '
Amir Xz
Amir Xz 2018년 8월 18일
If you want to open a MAT-file, use this one:
A = open('filename.mat');
Or, A = open('fullpath\filename.mat');
fullpath: is MAT-file's path.

댓글을 달려면 로그인하십시오.

답변 (2개)

Amir Xz
Amir Xz 2018년 8월 18일
Did you use "clear" at the first line of your code?
Or, another probability is: You added a folder into MATLAB path,that you have another function with the same name in that.
  댓글 수: 3
Image Analyst
Image Analyst 2018년 8월 18일
This is not an m-file. It appears to be a .mat file. Kelil, please answer my questions below, and dpb's questions above so we can quit wasting time.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2018년 8월 18일
If your function is called snafu.m, then do this on the command line:
>> which -all snafu
And you may have left over variables from a prior run still hanging around in memory that may be affecting your values on subsequent runs. So you might want to call clearvars before each run to clear those out.
And please answer dpb's question since I have no idea what you're asking either. And attach your script and any data files it needs to run.
  댓글 수: 3
Image Analyst
Image Analyst 2018년 8월 18일
Use
save('result.mat', 'comm_r');
to save the results as a .mat format file, not a text format m-file.
Then to recall the variable from the .mat file, do this
s = load('result.mat');
comm_r = s.comm_r;
Walter Roberson
Walter Roberson 2018년 8월 18일
편집: Walter Roberson 2018년 8월 18일
The error seen could easily happen if you accidentally did a save giving the name of the .m file -- for example if you had done
save result.m -mat
If you had just done
save result
then MATLAB would know to use result.mat
Perhaps you used one of the figure menu items to save a figure and did not notice that you had accidentally selected the .m file as the output name.
If you did accidentally save a workspace over top of result.m then the result.m you had is gone, and you would need to recover it from backup (if you have one.) If you are fortunate you might have an autosaved version; see https://www.mathworks.com/company/newsletters/articles/automatically-save-backup-m-files-with-the-matlab-editor.html

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile 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!

Translated by