writematrix does NOT overwrite existing file
Mostrar comentarios más antiguos
In the new 2025a version, When trying to overwrite an existing file using writematrix, the old data does not change, but I also do not see an error message telling me that overwrite is (for whatever reason) is not possible. In other words: I run the script, it ends, and the new data is not in the file. I did not have this problem with any of the previous versions.
13 comentarios
Saeid
el 23 de Jun. de 2025
Matt J
el 23 de Jun. de 2025
Are you able to delete the file using the File Explorer (to show that it is not locked or corrupted)? Does it happen on every file?
Saeid
el 23 de Jun. de 2025
Matt J
el 23 de Jun. de 2025
Are you running Matlab as Administrator?
Saeid
el 23 de Jun. de 2025
the cyclist
el 23 de Jun. de 2025
Editada: the cyclist
el 23 de Jun. de 2025
I have not fully investigated yet, but I may have noticed some similar anomalies. In my case, they seem to be related to the case-sensitivity of the filenames not behaving in the way I would expect, and not quite the same as previous releases.
I have not yet got certain enough of what I am seeing to submit a bug report (or even to be certain it is a bug).
The point is, in ALL previous versions there was no porblem overwriting a file while executing writematrix.
Yes, but my point is, since you are the only one experiencing this, it must be something in your environment specifically, like file or folder access privileges. Can you request admin privileges for one more day just to test this?
Also, is this Windows 10 or Windows 11?
Saeid
el 23 de Jun. de 2025
writematrix() is silently failing !!
filename = tempname()
writelines(["9";"2";"5"], filename)
dbtype(filename)
filename2 = tempname()
writematrix([-8 4; 3 7], filename2)
[fid, msg] = fopen(filename2, 'r');
if fid < 0; error('failed to open file "%s" because "%s"', filename2, msg); end
data = fread(fid, '*char');
fclose(fid)
fprintf('%s\n', data);
dbtype(filename2)
delete(filename)
delete(filename2)
@Walter Roberson Your example produces a failure only because writematrix (unlike writelines) requires a file extension.
filename = tempname()
writelines(["9";"2";"5"], filename)
dbtype(filename)
filename2 = tempname()+".txt"
writematrix([-8 4; 3 7], filename2)
[fid, msg] = fopen(filename2, 'r');
if fid < 0; error('failed to open file "%s" because "%s"', filename2, msg); end
data = fread(fid, '*char');
fclose(fid)
fprintf('%s\n', data);
dbtype(filename2)
delete(filename)
delete(filename2)
Walter Roberson
el 23 de Jun. de 2025
You are right, I forgot about the file extension problem. I see from the documentation that the default is to add the extension ".txt"
Abhishek
el 2 de Jul. de 2025
@Saeid Hi, I beleive this problem has something do with the local environment of your machine. Can you try running this code in your machine, and try updating the values of matrix, and at each update run it. See if the contents of the file change or not:
data = [1 2 3; 4 5 6; 7 8 9];
filename = 'mydata.txt';
writematrix(data, filename);
Or maybe, you can post the minimal code so that I can reproduce it on my end.
Respuestas (0)
Categorías
Más información sobre Text Files en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!