I have a problem with writing data to file
1 view (last 30 days)
Show older comments
I have some data I would like to write them in csv file but I am getting erros regarding the fprintf as well as I can get the right decimal places that I wrote. [ Please see the code below ].
fid=fopen('mn21hmya2021.csv','wt');
fprintf(fid,'time_q2,reach,x_relative_hand,y_relative_hand,z_relative_hand\n');
fprintf(fid,'%.2f,%.4f,%.4f,%.4f%.4f\n', wanted_columns');
fclose(fid);
headers = {'time_q2','reach','x_relative_hand','y_relative_hand','z_relative_hand'}
write= array2table(wanted_columns, 'VariableNames', headers)
writetable(write,'mn21hmya2021.csv','Delimiter',',')
The errora are:
1- Invalid file identifier. Use fopen to generate a valid file identifier.
2- fprintf(fid,'time_q2,reach,x_relative_hand,y_relative_hand,z_relative_hand\n');
0 Comments
Answers (1)
Jan
on 7 Dec 2021
Edited: Jan
on 7 Dec 2021
The folder might be write protected. Check this in general:
[fid, msg] = fopen('mn21hmya2021.csv','wt');
assert(fid > 0, msg);
Prefer absolute path names. It is fragile to rely on the current path to be at an expected location.
2 Comments
Jan
on 7 Dec 2021
Fine. This means, that you do not have write permissions in the current folder. What is the current folder? See the output of the cd command.
See Also
Categories
Find more on MATLAB Report Generator in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!