Only Save the New Numerical Data to Text File
1 次查看(过去 30 天)
显示 更早的评论
I want to save the newly edited data to the same text file after clicking the save button.
I have 10 variables.
This is what I have for my edit data:
function EditButtonPushed(app, event)
app.T.ct(1) = app.ctEditField.Value;
app.T.cr(1) = app.crEditField.Value;
When saving the data:
Q = table2array(app.T(1, :));
fileid = fopen('filename.txt','w');
fprintf(fileid, '%6.5f ', (Q));
The textfile output is:
0.09000 0.45000 45.00000 0.00000 0.00600 0.24200 4.67000 4.00000 0.89925 1.00000 2.00000 2.00000 2.00000 2.00000 2.00000 2.00000 2.00000 2.00000 2.00000 2.00000
I edited each number to 2 and for some reason, my old data appears in front of my new data.
How do I only save the newly edited data?
0 个评论
回答(1 个)
Jan
2022-4-5
If you do not close a file opened by fopen with fclose is stays open.
Solution: Append an fclose(fileid) after the fprintf.
3 个评论
Jan
2022-4-6
Is the file still open? Try to close all open files:
fclose('all')
If you are still appending the data, you either open the file with 'a' instead of 'w', or the data are included in your array Q, although you expect something else.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!