fprintf cell array syntax
Ältere Kommentare anzeigen
Edit: Thanks, the answer I accepted shows the right syntax I needed to input the data into fprintf I am trying to use fprintf to create an input script for LAMMPS simulations and I ran into a problem when I was trying to input coordinates and orientations from matrices into the script.
for i = 1:length(crd)
fprintf(fid,{'region 1 sphere '},crd(i,:),{' '},r,{' units box\r\n'});
fprintf(fid,'delete_atoms region 1\r\n');
fprintf(fid,{'lattice fcc 3.52 orient x '},num2str(orn(i,1)),{' '},...
num2str(orn(i,2)),{' '},num2str(orn(i,3)),{' orient y '},...
num2str(orn(i,4)),{' '},num2str(orn(i,5)),{' '},num2str(orn(i,6)),...
{' orient z '},num2str(orn(i,7)),{' '},num2str(orn(i,8)),...
{' '},num2str(orn(i,9),'\r\n'));
end
This code gives an error of "Error using fprintf invalid format" The function FPRINTF is apparently called with a cell array.
The above code snippet is supposed to write in coordinates and orientations for many spheres, where crd(i,3) is a matrix of coordinates and orn(i,9) is the orientation in miller indices. Both matrices were double in structure but the crd was initialized as a character structure with num2str earlier in the script. The problem is with the way I call the cell array. I believe I am supposed to use %f and %d, I just don't know how to change my code to use them. An example of what I want printed out is this: region 1 sphere 10 10.5 20 20 units box delete_atoms region 1 lattice fcc 3.52 orient x 0 3 1 orient y 0 3 -1 orient z 1 0 0
The matrix of orientations are miller indices so they are all integers, while the matrix of coordinates will have decimals.
I hope my question was stated clearly enough. And my mistake if this has been already answered in previous questions.
Jonathan
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Hilbert and Walsh-Hadamard 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!