Hi all, im trying to print out some data into a specific format so it can be read into another program. The code i am enacting centers around this loop:
%Write section data
for i=1:nsections
fprintf(fileID2,'SECTION %1.0f\n',i);
row_start_index = 1 + (i-1)*54;
for j=1:npoints
row_index = row_start_index+(j-1);
fprintf(fileID2,'%12.8f %12.8f %12.8f %12.8f %12.8f \n',Data(row_index,1),Data(row_index,2),Data(row_index,3),Data(row_index,4),Data(row_index,5),Data(row_index,6));
end
end
The output should look like (ignore the 1. 2. 3. 4. ... some forum formatting thing)
Section 1
  1. # # # # #
  2. # # # # #
  3. # # # # #
  4. # # # # #
Section 2
  1. # # # # #
  2. # # # # #
  3. # # # # #
  4. # # # # #
and so on
but actually what i get is this:
Section 1
  1. # # # #
  2. # # # # #
  3. # # # # #
  4. # # # # #
  5. #Section 2
  6. # # # #
  7. # # # # #
  8. # # # # #
  9. # # # # #And so on..
it appears everything is shifted over by 1 number somehow.
I should mention i have played with /r/n and opening the file with the "wt" command
Anyone know why this is happening?
Any help would be greatly appreciated !
Thanks
Tyler

댓글 수: 1

Guillaume
Guillaume 2014년 10월 6일
To stop Answers from replacing your first # by a numbered list, write it as #

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

 채택된 답변

Oleg Komarov
Oleg Komarov 2014년 10월 6일

2 개 추천

You are printing a 5 column row:
'%12.8f %12.8f %12.8f %12.8f %12.8f \n'
but supplying 6 datatpoints:
Data(row_index,1),Data(row_index,2),Data(row_index,3),Data(row_index,4),Data(row_index,5),Data(row_index,6)
which you can write as
Data(row_index,1:6)

댓글 수: 3

fprintf(fileID2,'%12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n',...
Data(row_index,1:6));
Or
fprintf(fileID2,'%12.8f', Data(row_index,1:6));
fprintf(fileID2,'\n');
Tyler
Tyler 2014년 10월 6일
thank you, i am an idiot
Image Analyst
Image Analyst 2014년 10월 6일
Well, I wouldn't say that. Everyone make simple mistakes sometimes.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2014년 10월 6일

댓글:

2014년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by