% Simple script to compare some formatting options
% Written April 2010 by John Bell for CS 109

clc;
clear;

x = 0.0 : 0.25 : 1.0;
disp( 'disp' );
disp( [ 'x = ' num2str( x ) ] );

fprintf( '\nfprintf 1 \n' );
fprintf( 'x = %5.2f\n', x );

fprintf( '\nfprintf 2 \n' );
fprintf( 'x = ' );
fprintf( '%8.2f', x );
fprintf( '\n' );

sinX = sin( x );
disp( ' ' );
disp( 'fprintf with multiple columns ( doesn''t work right )' );
disp( '    X    sinx' );
fprintf( '%5.2f  %10.5f\n', x, sinX );

disp( ' ' );
disp( 'Try again ( no better )' );
disp( '    X    sinx' );
fprintf( '%5.2f  %10.5f\n', [ x', sinX' ] );

disp( ' ' );
disp( 'Doggone it, use loops!' );
disp( '    X    sinx' );
for i = 1:5
    fprintf( '%5.2f  %10.5f\n', x( i ), sinX( i ) );
end

disp( ' ' );
disp( ' Two wrongs make a right? ( Store columns in rows ) ' );
disp( '    X      sinx         10^6 * Sin(x)' );
array = [ x ; sinX; 1.0e6*sinX ];  % Row-wise
fprintf( '%5.2f  %10.5f  %17.5g\n', array );