MATLAB: Fprintf to display variables

align variables in text file

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

Best Answer

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