fprintf reading rows not working right...

조회 수: 1 (최근 30일)
Chris E.
Chris E. 2014년 8월 9일
답변: Image Analyst 2014년 8월 9일
Hello all!
Well I'm just not getting something, I'm sure its easy, but just not figuring it out. I'm just trying to read the rows and write them into a file. so the first row of the txt file should be 2 5 25 48 53, but that is not what I'm getting, I'm gettiing 2 14 11 9 4 4, well please help! Thanks, Here is the code:
nums = [2 5 25 48 53;
14 16 18 19 9;
11 31 4 44 52;
9 12 47 48 56;
4 14 29 4 56;
4 16 36 40 3;
1 22 39 2 46;
1 12 21 9 45;
14 6 17 33 7;
2 17 20 26 4;
10 20 45 1 3;
6 7 6 27 9;
1 0 22 23 8;
7 8 38 39 8];
fileID = fopen('Example.txt','w');
fprintf(fileID,'%1i\t %1i\t %1i\t %1i\t %1i\t %1i\n',nums);
fclose(fileID);

채택된 답변

Image Analyst
Image Analyst 2014년 8월 9일
It's going down the rows first since MATLAB is column major. You can try transposing it or just use a for loop
for row = 1 : size(nums, 1)
fprintf(fileID,'%d\t %d\t %d\t %d\t %d\t %d\n',nums(row, :));
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by