writematrix does NOT overwrite existing file

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 件のコメント

Matt J
Matt J 2025 年 6 月 23 日
編集済み: Matt J 2025 年 6 月 23 日
I can't reproduce that. Are you on Windows, or something else? Is the target file closed when you attempt to overwrite?
Saeid
Saeid 2025 年 6 月 23 日
I'm on windows, and the target files is closed.
Matt J
Matt J 2025 年 6 月 23 日
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
Saeid 2025 年 6 月 23 日
I can delete it in the file explorer. This happnes to every file and every file name. I write the output data into a .txt file.
Matt J
Matt J 2025 年 6 月 23 日
Are you running Matlab as Administrator?
Saeid
Saeid 2025 年 6 月 23 日
No, but I never ran it as admin. Typically I just receive admin rights for the installation, and those rights will expire the next day. The point is, in ALL previous versions there was no porblem overwriting a file while executing writematrix.
the cyclist
the cyclist 2025 年 6 月 23 日
編集済み: the cyclist 2025 年 6 月 23 日
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).
Matt J
Matt J 2025 年 6 月 23 日
編集済み: Matt J 2025 年 6 月 23 日
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
Saeid 2025 年 6 月 23 日
The 2025a version had many other bugs too. For example, it was not possible to copy, paste or remove files in the file explorer using shortycut keys (Ctrl+C and Ctrl+V, Ctrl+X). Now those bugs seem to have been resolved, but every now and then something new comes up. For some inexplicable reason, they have also completely eliminated the possibility of channging the format and size of the fonts in the explorer window.
Walter Roberson
Walter Roberson 2025 年 6 月 23 日
writematrix() is silently failing !!
filename = tempname()
filename = '/tmp/tp145a150f_600a_4251_b4ae_ac13b137997c'
writelines(["9";"2";"5"], filename)
dbtype(filename)
1 9 2 2 3 5
filename2 = tempname()
filename2 = '/tmp/tp1235bf78_6b51_41c2_b384_4507e228ec7f'
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
failed to open file "/tmp/tp1235bf78_6b51_41c2_b384_4507e228ec7f" because "No such file or directory"
data = fread(fid, '*char');
fclose(fid)
fprintf('%s\n', data);
dbtype(filename2)
delete(filename)
delete(filename2)
Matt J
Matt J 2025 年 6 月 23 日
@Walter Roberson Your example produces a failure only because writematrix (unlike writelines) requires a file extension.
filename = tempname()
filename = '/tmp/tp2b9aa2ee_4f94_4d2c_8213_1b957d4764fa'
writelines(["9";"2";"5"], filename)
dbtype(filename)
1 9 2 2 3 5
filename2 = tempname()+".txt"
filename2 = "/tmp/tp492cbb55_e0f7_4db6_9a8a_91c8b341d7e0.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)
ans = 0
fprintf('%s\n', data);
-8,4 3,7
dbtype(filename2)
1 -8,4 2 3,7
delete(filename)
delete(filename2)
Walter Roberson
Walter Roberson 2025 年 6 月 23 日
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
Abhishek 2025 年 7 月 2 日
@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.

サインインしてコメントする。

回答 (0 件)

製品

リリース

R2025a

質問済み:

2025 年 6 月 23 日

コメント済み:

2025 年 7 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by