MATLAB: In fortran if I have a large number of similarly formatted columns to print I just multiply the format spec with the number. For example 12f8.2. This will print 12 columns at f8.2. Can I do this in Matlab using fprintf

fprintf

Fortran: WRITE(2,"(10F5.2)")
Matlab: fprintf(fid,'I want n %f columns \n',output)

Best Answer

No. But you can repmat() a format string the number of times you want. You will usually want to add \n on. For example,
fmt = [repmat('%5.2f', 1, 10), '\n'];
fprintf(fid, fmt, output.' )
Notice the .' after "output". If "output" is a 2D array with 10 columns, then you need to transpose that to be 10 rows to get the values to print out in column formats. It is not intuitive, but it is entirely consistent with the way MATLAB accesses arrays.
Related Question