我已经编写了以下代码,并且我需要仅对第 6、7、8 列进行操作,如图所示,但我希望结果 .pdb 文件也包含输入文件中的其他列。那就是我只想用最终结果替换输入文件的第6,7,8列而不影响其他列。我无法弄清楚这一点。
%
phi1 =188.7*pi/180;
PHI = 82.3*pi/180;
phi2 = 150.4*pi/180;
%%%%% to be change ary euler angles
%%%%%%% rotation_matrix defining
R(1,1) = cos(phi1)*cos(phi2)-sin(phi1)*sin(phi2)*cos(PHI);
R(1,2) = sin(phi1)*cos(phi2)+cos(phi1)*sin(phi2)*cos(PHI);
R(1,3) = sin(phi2)*sin(PHI);
R(2,1) = -cos(phi1)*sin(phi2)-sin(phi1)*cos(phi2)*cos(PHI);
R(2,2) = -sin(phi1)*sin(phi2)+cos(phi1)*cos(phi2)*cos(PHI);
R(2,3) = cos(phi2)*sin(PHI);
R(3,1) = sin(phi1)*sin(PHI);
R(3,2) = -cos(phi1)*sin(PHI);
R(3,3) = cos(PHI);
%%output
rotationMatrix=R;
fid2 = fopen('final_result.pdb','wt');
for k=1:100
fid = fopen('ipp31.pdb');
A = textscan(fid, '%s %s %f %s %s %f %f %f %s ') ;
%read the file
a = A{6};
b = A{7};
c = A{8};
p=[a b c];
p_t=p.';
M=rotationMatrix*p_t;
M_T=M.';
fid = fopen('ipp31.pdb', 'wt'); % Open for writing
fprintf(fid,' %f\t %f\t %f\n',M_T);
fclose(fid);
%
textfilename = [num2str(k) '.pdb'];
fid1 = fopen(textfilename,'wt');
fprintf(fid1,' %f\t %f\t %f\n',M_T);
fclose(fid1);
fprintf(fid2,' %f\t %f\t %f\n',M_T);
end
fclose(fid2);