file - What is wrong with this loop? FprintF in matlab -
i have loop supposed search through file , add text
fid = fopen('wave_propagation_var5_alpha1delta1.cps_001', 'rt+') fprintf(fid, 'dsadsado') =1:383 currentline = fgetl(fid) currentline = strtrim(currentline) if strcmp(currentline, '$$solid_anormal')==1 fprintf(fid, 'hello') elseif strcmp(currentline, '$$solid_deltanormal')==1 fprintf(fid, num2str(deltalist(i))) else end i=i+1 end
line 2 appears print file correctly. cannot figure out why lines 7 , 9 won't. when debug if statement satisfied , code goes both lines , executes them. when open target file dont understand why nothing happening....
please help. thanks.
it bad idea try actively read , write same file in matlab. you'll instead want use different file output.
fin = fopen('wave_propagation_var5_alpha1delta1.cps_001', 'rt+'); fout = fopen('wave_propagation_var5_alpha1delta1.cps_001.out', 'w'); =1:383 currentline = fgetl(fin) currentline = strtrim(currentline) if strcmp(currentline, '$$solid_anormal')==1 fprintf(fout, 'hello') elseif strcmp(currentline, '$$solid_deltanormal')==1 fprintf(fout, num2str(deltalist(i))) end % print newline every time correspondence fprintf(fout, '\n') i=i+1 end fclose(fin) fclose(fout) % replace input file output file if want movefile('wave_propagation_var5_alpha1delta1.cps_001.out', ... 'wave_propagation_var5_alpha1delta1.cps_001');
Comments
Post a Comment