How to write xyz files
61 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
KSSV
2019-6-18
Let A(x,y,z) be your m*3 array.
fid = fopen('test.txt') ;
fprintf(fid,'%f %f %f\n', A') ;
fclose(fid) ;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!