Problem using fprintf, extra character printed each line

7 次查看(过去 30 天)
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

采纳的回答

Image Analyst
Image Analyst 2013-10-13
Try this:
results_file = 1; % Let's use the command window until we get it figured out.
fprintf(results_file,'SASA for Individual Atoms: \n');
for k = 1 : 855
fprintf(results_file,'Atom %d %s: %.3f\n', k, atomName{k}, atomSASA(k));
end
Remember to get rid of the results_file = 1; line once you have it debugged!

更多回答(1 个)

per isakson
per isakson 2013-10-13
Hint:
>> char( 33:80 )
ans =
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOP
it's the counter, i, that causes the extra character
>> sprintf('%s', 33:37 )
ans =
!"#$%

类别

Help CenterFile Exchange 中查找有关 Continuous Wavelet Transforms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by