필터 지우기
필터 지우기

Cannot save a .m file

조회 수: 21 (최근 30일)
Manjunath Navalgund
Manjunath Navalgund 2016년 5월 19일
편집: Walter Roberson 2019년 12월 5일
Its simple and It has been asked a 100 times on the forum. New >> Script a= 1; b= 2; c = a+b; bla bla blah save. - does not work , the file is not saved I have no clue what is happening. Please help

답변 (3개)

Mate Misho
Mate Misho 2019년 4월 19일
I had a similar problem and solved it. Whoever reads this should check his folderpath if any folder name has a space. I changed it to '_' and saving worked just fine.

John D'Errico
John D'Errico 2016년 5월 19일
Simple. You probably do not have write access to that directory. You cannot write a file to a directory where you are not allowed to write. Period. In some rare cases, you simply lack the room to write a file, but that would be RARE.
This is not a MATLAB issue, but your computer.
Either choose a directory where you do have write access, or change the permissions on that directory. Again, this is not in the control of MATLAB.
  댓글 수: 1
James Cavenaugh
James Cavenaugh 2017년 5월 18일
편집: Walter Roberson 2019년 12월 5일
John, if it were that simple, do you think it would be asked "100 times" as Manjunath exaggeratingly stated? I've got this problem too, and I certainly have write permission to the folder in question. I can open a text editor (I use Notepad++), save the code there along the lines of "my_function.m" and it saves just fine. That's a work-around, not a solution. Clearly I have write permission. It DOES have to do with Matlab, someway, somehow. Matlab ignores its Save and Save As commands, somehow. By the way, I tried the advice posted at https://www.mathworks.com/matlabcentral/newsreader/view_thread/325983 and got this:
>> [fid, errormessage] = fopen('test1.m', 'wt')
fid =
3
errormessage =
0×0 empty char array
>> [fid, errormessage] = fopen('is_even.m', 'wt')
fid =
4
errormessage =
0×0 empty char array
In these cases a blank file was created, just not when trying to save a new, untitled .m file using Matlab's editor.
My Matlab editor was still open, so I then tried to save it again, after selecting the (blank) .m file with the name "is_even.m". I clicked Save, the editor asked if I wanted to overwrite the existing file of the same name, I affirmed I did, and it looked as if it succeeded in that there was no error given. So then I wanted to check this, and I opened up the file in Notepad++, but alas, the file was still blank. I selected all from the Matlab editor, pasted it into the Notepadd++ editor, and saved it. I tried to edit again in the Matlab editor, clicked Save, but I noticed that instead of Save, it was Save As that was asking me if I wanted to overwrite the existing file. Why is Save As being activated when Save should be? The file already exists and I should be able to save changes to it. I shut down and restarted Matlab, selected the file, made a small edit, and saved it just fine. Obviously: (1) other people have this problem, so it seems pretty common, (2) it's been around a while (I'm using 2017A on a Windows 7 machine, but it's been around since at least 2013 or 2014), (3) it's a Matlab issue, not a file permissions issue, and (4) it's got an easy enough workaround but it still should've been fixed a couple of years ago; it's a real annoyance.

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


Bao Le
Bao Le 2019년 12월 5일
Check the folder where you save it and check the path

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by