Problem using fprintf, extra character printed each line
Ältere Kommentare anzeigen
I have two data structures:
atomName <855*1 cell>
atomSASA <855*1 double>
which I am using in code to produce an output file:
%write out SASA values for individual atoms to file
results_file = fopen('output.txt','w');
fprintf(results_file,'SASA for Individual Atoms: \n');
i=1;
while i < (855)
fprintf(results_file,'Atom %s %s: %.3f\n',i,cell2mat(atomName(i)),atomSASA(i));
i = i + 1;
end
The file seems correct for the first 32 lines, but starting at line 33, there is an extra character after the word Atom. The character changes each line, eventually going through digits, capital letters A-Z, lower letters a-z etc. I would like to remove this extra character from each line:
Atom ! HG23: 6.286
Atom " N: 0.000
Atom # CA: 0.000
Atom $ C: 0.000
Atom % O: 0.000
Atom & CB: 0.000
Atom ' CG: 0.000
Atom ( CD1: 0.000
Atom ) CD2: 0.000
Atom * CE1: 0.000
Atom + CE2: 0.000
Atom , CZ: 0.000
Atom - OH: 0.000
Atom . H: 0.000
Atom / HA: 0.000
Atom 0 HB2: 0.000
Atom 1 HB3: 0.000
Atom 2 HD1: 0.000
Atom 3 HD2: 0.000
Atom 4 HE1: 0.000
Atom 5 HE2: 0.000
Atom 6 HH: 0.000
Atom 7 N: 0.000
Atom 8 CA: 0.000
Atom 9 C: 0.000
Atom : O: 0.000
Atom ; CB: 0.000
Atom < CG: 0.000
Atom = CD: 0.000
Atom > CE: 1.208
Atom ? NZ: 1.312
Atom @ H: 0.000
Atom A HA: 0.000
Atom B HB2: 0.000
Atom C HB3: 0.000
Atom D HG2: 0.000
Atom E HG3: 0.000
Atom F HD2: 0.000
Atom G HD3: 0.000
Atom H HE2: 0.000
Atom I HE3: 33.979
Atom J HZ1: 0.000
Atom K HZ2: 0.000
Atom L HZ3: 44.513
Atom M N: 0.000
Atom N CA: 0.000
Atom O C: 0.000
Atom P O: 0.000
Atom Q CB: 0.000
Atom R CG: 0.000
Atom S CD1: 0.000
Atom T CD2: 0.000
Atom U H: 0.000
Atom V HA: 0.000
Atom W HB2: 0.000
Atom X HB3: 0.000
Atom Y HG: 0.000
Atom Z HD11: 0.000
Atom [ HD12: 0.000
Atom \ HD13: 0.000
Atom ] HD21: 0.000
Atom ^ HD22: 0.000
Atom _ HD23: 0.000
Atom ` N: 0.000
Atom a CA: 0.000
Atom b C: 0.000
Atom c O: 0.000
Atom d CB: 0.000
Atom e CG1: 0.000
Atom f CG2: 0.000
Akzeptierte Antwort
Weitere Antworten (1)
per isakson
am 13 Okt. 2013
Hint:
>> char( 33:80 )
ans =
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOP
it's the counter, i, that causes the extra character
>> sprintf('%s', 33:37 )
ans =
!"#$%
Kategorien
Mehr zu Continuous Wavelet Transforms finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!