matlab fprintf error? please help

5 visualizaciones (últimos 30 días)
Sojung Youn
Sojung Youn el 28 de Sept. de 2020
Comentada: Walter Roberson el 29 de Sept. de 2020
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!

Respuestas (1)

per isakson
per isakson el 29 de Sept. de 2020
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 comentario
Walter Roberson
Walter Roberson el 29 de Sept. de 2020
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.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by