% print_format_test.m  2011-11-14
% test of different format strings when printing out values 
%
clear;clc;
disp(sprintf(' MATLAB example: print_format_test.m'));
%
% Summary of character format codes
% floating point   %f, %g
% single character  %c
% character string  %s
% integer  %d
% octal (base 8 integer) %o
% hexadecimal (base 16 integer) %X

header_separator = '============================================================';

%%% floating point examples -----------------------------------------%
message= 'Examples of formatting strings for a floating point variable';
disp(sprintf('%s \n', header_separator, message, header_separator));

val = 4.0*atan(1.0)
disp(sprintf('val (in f format) = %9.5f \n', val));
disp(sprintf('val (in e format) = %14.4e \n', val));

%%% integer examples -----------------------------------------%
message= 'Examples of formatting strings for an integer variable';

disp(sprintf('%s \n', header_separator, message, header_separator));

count = 25;

disp(sprintf('Count (decimal) = %d \n', count));
disp(sprintf('Count = (octal) = %o \n', count));
disp(sprintf('Count = (hexadecimal) = %X \n', count));

% using both a string and a value
disp(sprintf('%s %3.3d %s \n', 'Count value is equal to ', count, 'units.'));

%%%-------------------------------------------------------------------------------%
