Hi everyone,
I would ask some trick to write atom number in xyz file created from Nx1 char array (atom_n) and Nx3 matrix (X_ads).
I'm doing struct array with:
struct_XYZ=struct( 'atom_n' , atom_n , 'X_ads' , X_ads );
and after converting to dataset:
structXYZdata = struct2dataset( struct_XYZ );
I'm able to export to .xyz file with:
export(structXYZdata,'file','myfile.xyz');
My problem is how to add the number of atoms in the first line of file, leave blank the second line and write data from the third line? So i can open this file directly with molecular editor without any manually modification.
Thanks in advance,
Francesco

답변 (1개)

KSSV
KSSV 2019년 6월 18일

0 개 추천

Let A(x,y,z) be your m*3 array.
fid = fopen('test.txt') ;
fprintf(fid,'%f %f %f\n', A') ;
fclose(fid) ;

댓글 수: 1

frank90
frank90 2019년 6월 18일
Thank so much,
I tryed to write whit fprintf command like you suggested me with these modification:
fID = fopen('myfile.xyz , 'w');
fprintf(fID,'%d\n',N); %to add number of atoms to first line
fprintf(fID,'\n'); %to leave one blank line
for i=1:N-1
fprintf(fID,'N %16.10f %16.10f %16.10f\n' , X_ads(i,:));
end
fprintf(fID,'N %16.10f %16.10f %16.10f' , X_ads(N,:));
fclose(fID);
Finally I obtained the file but now I have the reverse problem. Ho to have back X_ads matrix from these file?
importdata command that I was using before don't function for these type of files.
Thanks
Francesco

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2019년 6월 18일

댓글:

2019년 6월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by