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 件のコメント
Saeid
2025 年 6 月 23 日
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
2025 年 6 月 23 日
Matt J
2025 年 6 月 23 日
Are you running Matlab as Administrator?
Saeid
2025 年 6 月 23 日
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).
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
2025 年 6 月 23 日
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
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
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 件)
カテゴリ
ヘルプ センター および File Exchange で Text Files についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!