Cannot save a .m file
18 views (last 30 days)
Show older comments
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
0 Comments
Answers (3)
Mate Misho
on 19 Apr 2019
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.
0 Comments
John D'Errico
on 19 May 2016
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 Comment
James Cavenaugh
on 18 May 2017
Edited: Walter Roberson
on 5 Dec 2019
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.
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!