matlab fprintf error? please help

조회 수: 1 (최근 30일)
Sojung Youn
Sojung Youn 2020년 9월 28일
댓글: Walter Roberson 2020년 9월 29일
Hi all,
I am very very new to matlab, and I am trying to run a script that will read my txt files and write it on my xlsx file. I have about 120 txt files, so I am trying to run a script on them, but I keep having this fprintf error on a part of my script.
fid = fopen(sprintf('%s/Timeseries.ROIs/%s_timeseries.xlsx',rootdir,rois{roi}),'w');
colhdrs = {'Subject','Group','Gender','Subject','Condition','-4.4', '-2.2', '0', '2.2', '4.4', '6.6', '8.8', '11', '12.2'};
fprintf(fid,'%s\t',colhdrs{:}); fprintf(fid,'\n');
I keep facing an error with the script line below.
frpintf(fid, '%s \ t', colhdrs {:});
saying that it has Invalid file identifier. Use fopen to generate a valid file identifier.
Again, I am very new so any help would be much appreciated. Thank you so much!

답변 (1개)

per isakson
per isakson 2020년 9월 29일
Most likely, fid = fopen(...), failed and return a negative value to fid.
Replace
fid = fopen(sprintf('%s/Timeseries.ROIs/%s_timeseries.xlsx',rootdir,rois{roi}),'w');
by
ffs = fullfile( rootdir, 'Timeseries.ROIs', [rois{roi},'_timeseries.xlsx'] );
[fid,msg] = fopen( ffs, 'w' );
and run the script and inspect the values of ffs, fid and msg.
  댓글 수: 1
Walter Roberson
Walter Roberson 2020년 9월 29일
And remember that when you fopen() a file for 'w', that the underlying operating system will not automatically create any missing directories. If rootdir is not a directiory, or if Timeseries.ROIs is not a directory within rootdir, then the fopen() would fail.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by