This is my code for a function that takes two files and combines parts of these files into one new file.
function []=CreateNewMarkersEEGlab(pNumber)dataFileName=strcat(int2str(pNumber),'_logfile.txt');fid = fopen(dataFileName);C = textscan(fid, '%s%s%s%s%s%s%s%s%s%s%s%s%s%s', 'headerlines', 1);rScore=C{12}; sNumber=C{5};cNumber=C{6};subNumber=C{7};tcode=C{10}; fclose(fid);% compute the new marker
for i=1:156 if rScore{i}=='1' respMarker='corrresp'; else respMarker='incorrresp'; end if tcode{i}=='1' corrMarker='corr'; else corrMarker='incorr'; end newMarker(i)= strcat('S1_con',cNumber(i),'_sub',subNumber(i),'_',corrMarker,'_',respMarker,'_SNr',sNumber(i)); end% read the old marker file
dataFileName=strcat('EEG_Anne_',int2str(pNumber),'.vmrk');fid = fopen(dataFileName);headline1=fgets(fid);headline2=fgets(fid);headline3=fgets(fid);headline4=fgets(fid);headline5=fgets(fid);headline6=fgets(fid);headline7=fgets(fid);headline8=fgets(fid);headline9=fgets(fid);headline10=fgets(fid);headline11=fgets(fid);headline12=fgets(fid);headline13=fgets(fid);C = textscan(fid, '%s%s%d%d%d','Delimiter',',');Type=C{1};Position=C{3};Length=C{4};Channel=C{5};fclose(fid);% rewrite the new marker file
outFileName=strcat('EEG_Anne_',int2str(pNumber),'_new.vmrk');fid = fopen(outFileName,'w+');fprintf(fid,headline1);fprintf(fid,headline2);fprintf(fid,headline3);fprintf(fid,headline4);fprintf(fid,headline5);fprintf(fid,headline6);fprintf(fid,headline7);fprintf(fid,headline8);fprintf(fid,headline9);fprintf(fid,headline10);fprintf(fid,headline11);fprintf(fid,headline12);fprintf(fid,headline13);for i=1:156 temp=[Type(i),',', newMarker(i),',', num2str(Position(i)),',',num2str(Length(i)),',',Channel(i),'\r\n']; fprintf(fid,temp);endfclose(fid);
The error code I get refers to the second last line and reads this:
Error using fprintf Invalid format.
Error in CreateNewMarkersEEGlab (line 73) fprintf(fid,temp);
What am I doing wrong? Thanks a lot for your help!
Best Answer