Effacer les filtres
Effacer les filtres

I have a problem with writing data to file

2 vues (au cours des 30 derniers jours)
Hassen Mohamed Yousif Abdelatif
Commenté : Jan le 7 Déc 2021
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');

Réponses (1)

Jan
Jan le 7 Déc 2021
Modifié(e) : Jan le 7 Déc 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 commentaires
Hassen Mohamed Yousif Abdelatif
Thanks for replying .
That does not work and it gave me ' Permission denied' .
Jan
Jan le 7 Déc 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Entering Commands dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by