fprintf reading rows not working right...
2 ビュー (過去 30 日間)
古いコメントを表示
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);
0 件のコメント
採用された回答
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 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!