How do I print one value on one row and another on the next
So I have a matrix which I am trying to print into a file so that one row has one value the next row a different and so one. The first collum in each row should alternate between B and N, which it is doing, however the rest of the row values are the same. For example here is the first four rows of the printed file :
B 55.31897464 3.07237728 -1002.88631401
N 55.31897464 3.07237728 -1002.88631401
B 53.43739489 3.94977174 -1001.67387801
N 53.43739489 3.94977174 -1001.67387801
Instead of the N row being the same as the B row I would like the file to be printed as:
B 55.31897464 3.07237728 -1002.88631401
N 53.43739489 3.94977174 -1001.67387801
Attatched is my code :
for i = 1:2:size(unit,1)
fprintf(fid_1, ‘%s %10.8f %10.8f %10.8frn’,’B’,unit(i,1),unit(i,2),unit(i,3)); %print boron atoms
fprintf(fid_1, ‘%s %10.8f %10.8f %10.8frn’,’N’,unit(i,1),unit(i,2),unit(i,3)); %print nitrogen atoms
endSo I have a matrix which I am trying to print into a file so that one row has one value the next row a different and so one. The first collum in each row should alternate between B and N, which it is doing, however the rest of the row values are the same. For example here is the first four rows of the printed file :
B 55.31897464 3.07237728 -1002.88631401
N 55.31897464 3.07237728 -1002.88631401
B 53.43739489 3.94977174 -1001.67387801
N 53.43739489 3.94977174 -1001.67387801
Instead of the N row being the same as the B row I would like the file to be printed as:
B 55.31897464 3.07237728 -1002.88631401
N 53.43739489 3.94977174 -1001.67387801
Attatched is my code :
for i = 1:2:size(unit,1)
fprintf(fid_1, ‘%s %10.8f %10.8f %10.8frn’,’B’,unit(i,1),unit(i,2),unit(i,3)); %print boron atoms
fprintf(fid_1, ‘%s %10.8f %10.8f %10.8frn’,’N’,unit(i,1),unit(i,2),unit(i,3)); %print nitrogen atoms
end So I have a matrix which I am trying to print into a file so that one row has one value the next row a different and so one. The first collum in each row should alternate between B and N, which it is doing, however the rest of the row values are the same. For example here is the first four rows of the printed file :
B 55.31897464 3.07237728 -1002.88631401
N 55.31897464 3.07237728 -1002.88631401
B 53.43739489 3.94977174 -1001.67387801
N 53.43739489 3.94977174 -1001.67387801
Instead of the N row being the same as the B row I would like the file to be printed as:
B 55.31897464 3.07237728 -1002.88631401
N 53.43739489 3.94977174 -1001.67387801
Attatched is my code :
for i = 1:2:size(unit,1)
fprintf(fid_1, ‘%s %10.8f %10.8f %10.8frn’,’B’,unit(i,1),unit(i,2),unit(i,3)); %print boron atoms
fprintf(fid_1, ‘%s %10.8f %10.8f %10.8frn’,’N’,unit(i,1),unit(i,2),unit(i,3)); %print nitrogen atoms
end matrix manipulation, odd, even MATLAB Answers — New Questions