I am using fprinf to save results in a text file. However, my results are not aligned. This is how my text file looks like right now. Is there a way to allign these values so that I can analyze them easily in excel.
1.000000 45.000000 3.907000 196.067603 6.000000 11.000000 13.000000
2.000000 6.000000 5.109000 196.067603 6.000000 11.000000 13.000000
3.000000 6.000000 5.372000 90.000000 6.000000 11.000000 13.000000
4.000000 4.000000 5.536000 81.000000 6.000000 11.000000 13.000000
5.000000 1.000000 5.691000 72.900000 6.000000 11.000000 13.000000

1 件のコメント

Stephen23
Stephen23 2018 年 3 月 26 日
Excel reads CSV files, so why not simply create a CSV file?
Or even an Excel .xlsx file?

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2018 年 3 月 26 日

0 投票

If you put commas instead of spaces then excel could read it as a csv file.
You might want to use dlmwrite() or csvwrite() to make it easier.
Or you could just use a width specification in your fprintf:
>> fprintf('%12.6f %12.6f %12.6f\n', [1 45 3.907;2 6 5.109].')
1.000000 45.000000 3.907000
2.000000 6.000000 5.109000

6 件のコメント

Isha Sharma
Isha Sharma 2018 年 3 月 26 日
how can I use dlmwrite?
Isha Sharma
Isha Sharma 2018 年 3 月 26 日
a_det is a vector and it's size keeps changing. For example, a_det foe some iterations could be 1x3 and for some it could be 1x5. How do I display this?
fid = fopen('ADMM_Release.csv','wt');
for k1 = 1:1000
for k2 = 1:200
fprintf(fid, '%12.6f %12.6f %12.6f %12.6f %12.6f %12.6f %12.6f\n', k1, k2, time_Release_MIQP, rho, a_det ) ;
end
end
fclose(fileID);
Walter Roberson
Walter Roberson 2018 年 3 月 27 日
When that happens, do you want to output one of the a_det on each line with the same k1, k2, time_Release_MIQP, rho for each? Or do you want to output all of the a_det on the same line?
Isha Sharma
Isha Sharma 2018 年 3 月 27 日
all a_det on the same line. For example, k1=2, k2=45, a_det = [3;5;7]
or k1=3, k2=34, a_det = [2;5;7;9;4]
Walter Roberson
Walter Roberson 2018 年 3 月 27 日
    fid = fopen('ADMM_Release.csv','wt');  
    for k1 = 1:1000
          for k2 = 1:200
              fprintf(fid, '%12.6f %12.6f %12.6f %12.6f', k1, k2, time_Release_MIQP, rho);
              fprintf(fid, ' %12.6f', a_det ) ;
              fprintf(fid, '\n');
          end
      end
      fclose(fileID);
Isha Sharma
Isha Sharma 2018 年 3 月 29 日
Thank you , this works :)

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by