PDA

View Full Version : Matlab fprintf


Juanka
Apr22-11, 07:20 PM
ok I know how to code an fprintf if I am printing a value, but I want to make a "title" print for example.


Mass Time Error
fprintf values here. ........ .......... .............
fprintf values here............ ......... ...........



How do I fprintf the line that has mass, time and error???

Mark44
Apr22-11, 08:07 PM
Here's a link to the Matlab documentation for fprintf. I haven't used it in Matlab (don't have this software), but it looks about the same as the C standard library fprintf function.

If you want to print three floating point numbers to the screen on a single line, you can do it this way:

fprintf('%f %f %f\n', mass(i), time(i), error(i));

jhae2.718
Apr22-11, 09:05 PM
Mark44 is correct.

If you have the value in a matrix, I would do the following:

fprintf('%f %f %f\n', data');

where data is a matrix with columns mass, time, and error.

You'll want to read up on the appropriate string formats for your data.

Juanka
Apr22-11, 09:27 PM
I already have the data printed for example I have the following code, but I want to make a "title line"





%%%%I WANT a TITLE HERE%%%% FOR EXAMPLE%%%%

%fprintf(' seconds kg error')

fprintf(' Euler Step-10 %7.1f \t\t%.2f \t\t%.4f \n',Opti_Euler_step10,Mass_1,PE_Euler10)

fprintf(' Euler Step-500 %7.1f \t\t%.2f \t\t%.4f \n',Opti_Euler_step500,Mass_2,PE_Euler500)

fprintf(' Heun Step-10, & 1-ITER %7.1f \t\t%.2f \t\t%.4f \n',Opti_Heun_step10,Mass_3,PE_Heun10_1)

fprintf(' Heun Step-10, & 100-ITER %7.1f \t\t%.2f \t\t%.4f \n',Opti_Heun_step10_Iter100,Mass_7,PE_Heun10_100)

fprintf(' Heun Step-500, & 1-ITER %7.1f \t\t%.2f \t\t%.4f \n',Opti_Heun_step500,Mass_4,PE_Heun500_1)

fprintf('Heun Step-500, & 100-ITER %7.1f \t\t%.2f \t\t%.4f \n',Opti_Heun_step500_Iter100,Mass_8,PE_Heun500_10 0)

fprintf(' Runge-Kutta Step-10 %7.1f \t\t%.2f \t\t%.4f \n',Opti_RungeKutta_step10,Mass_5,PE_RK10)

fprintf(' Runge-Kutta Step-500 %7.1f \t\t%.2f \t\t%.4f \n',Opti_RungeKutta_step500,Mass_6,PE_RK500)

fprintf(' Golden Search %7.1f \n',Opti_Golden)

jhae2.718
Apr22-11, 09:32 PM
Just use fprintf with the title in a string.

MATLABdude
Apr23-11, 05:02 AM
Are you trying to make your title stand out (e.g. bold or flashing font)? Unfortunately, you can't do this in the MATLAB command-line (the 'text' function only works on graphics). Nevertheless, the state-of-the-art of text-based gaming and ASCII art (along with standard underscores and dashes) is available to you:
http://en.wikipedia.org/wiki/ASCII_art
http://en.wikipedia.org/wiki/Star_Trek_%28text_game%29

Why yes, I did grow up in the 80s / 90s!

jhae2.718
Apr23-11, 10:26 AM
I'll usually do something like:

fprintf('Awesome Table Title\n');
fprintf('-------------------\n');
% print data here

Though half the time I write my m-files so that they print tables formatted for LaTeX.