MATLAB: How to write data in an appointed data format

data format output write

Dear colleagues,
I have a column data:
44566
44567
44568
44565
44566
4565
44563
99999
44561
44563
44564
but I want to convert my data into the following data format, e.g., 6f12.4 would imply six values per row each twelve characters long with four decimal places.
4565.000 44566.000 44567.000 44568.000 44565.000 44566.000
4565.000 44563.000 99999.000 44561.000 44563.000 44564.000
…..
Could you give me some good suggestions? Many thanks!

Best Answer

It would imply that in FORTRAN but not MATLAB.
You would have to do something like this:
v = [44566
44567
44568
44565
44566
4565
44563
99999
44561
44563
44564
44567];
fid = 1; % Here ‘1’ Is ‘stdout’, The Command Window, But You Would Use The ‘fopen’ Function To Write To A File
fprintf(fid, '%12.4f\t%12.4f\t%12.4f\t%12.4f\t%12.4f\t%12.4f\n', v)
producing:
44566.0000 44567.0000 44568.0000 44565.0000 44566.0000 4565.0000
44563.0000 99999.0000 44561.0000 44563.0000 44564.0000 44567.0000