필터 지우기
필터 지우기

I have a problem with writing data to file

조회 수: 2 (최근 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 CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by