I have a problem with writing data to file

1 回表示 (過去 30 日間)
Hassen Mohamed Yousif Abdelatif
Hassen Mohamed Yousif Abdelatif 2021 年 12 月 7 日
コメント済み: Jan 2021 年 12 月 7 日
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');

回答 (1 件)

Jan
Jan 2021 年 12 月 7 日
編集済み: Jan 2021 年 12 月 7 日
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 件のコメント
Hassen Mohamed Yousif Abdelatif
Hassen Mohamed Yousif Abdelatif 2021 年 12 月 7 日
Thanks for replying .
That does not work and it gave me ' Permission denied' .
Jan
Jan 2021 年 12 月 7 日
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.

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

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by