Home > published > velocityTable.m

velocityTable

PURPOSE ^

Example of how to print a nicely formatted table

SYNOPSIS ^

function velocityTable

DESCRIPTION ^

Example of how to print a nicely formatted table
Calls anyToMeters_gen and anyToSeconds to do the real work.

USAGE: >>velocityTable

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

function  velocityTable
%Example of how to print a nicely formatted table
%Calls anyToMeters_gen and anyToSeconds to do the real work.
%
%USAGE: >>velocityTable

fprintf('\n\nVELOCITY CONVERSION\n');
disp('Distance Abbreviations: ft=feet, rd=rods, fr=furlongs, m_=meter, in=inches, mi=miles');
disp('Time Abbreviations: h=hours, m=minutes, s=seconds, f=fortnights, d=days');
disp(' ')
fprintf('%10s %8s%4s%6s%3s\t%9s%4s \n','Velocity','Distance','Per','Time','=','Converted','m/s');
fprintf('%10s %8s%4s%6s%3s\t%9s%4s \n','--------','--------','---','----','-',',--------','---');

%Define the table formats
formatFloat='%10.3f %8s%4s%6s%3s\t%9.3f%4s \n';
%If the above makes no sense ... try looking here:
%http://www.coderwiki.com/wiki/index.php?title=C:Format_string
%Matlab's fprintf borrows all the formatting stuff from C's printf.
%This may also help http://publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html
%If you read these, remember that it isn't C, and you don't have to worry
%about all the C stuff.  Just look at how they define formatted output with
%printf and fprintf.
velocity=1E5; distanceUnit='ft'; timeUnit='d'; 
disp('Students -- This function WILL NOT WORK until you write anyToMeters and anyToSeconds')
disp('But you can hack in something temporarily to see how it will work')
vOutput=velocity*anyToMeters(1,distanceUnit)/anyToSeconds(1,timeUnit);
fprintf(formatFloat,velocity,distanceUnit,'per',timeUnit,' =',vOutput,'m/s');

velocity=12345; distanceUnit='in'; timeUnit='s'; 
vOutput=velocity*anyToMeters(1,distanceUnit)/anyToSeconds(1,timeUnit);
fprintf(formatFloat,velocity,distanceUnit,'per',timeUnit,' =',vOutput,'m/s');

velocity=1000; distanceUnit='fr'; timeUnit='f'; 
vOutput=velocity*anyToMeters(1,distanceUnit)/anyToSeconds(1,timeUnit);
fprintf(formatFloat,velocity,distanceUnit,'per',timeUnit,' =',vOutput,'m/s');

velocity=100*pi; distanceUnit='rd'; timeUnit='m'; 
vOutput=velocity*anyToMeters(1,distanceUnit)/anyToSeconds(1,timeUnit);
fprintf(formatFloat,velocity,distanceUnit,'per',timeUnit,' =',vOutput,'m/s');

velocity=60; distanceUnit='mi'; timeUnit='h'; 
vOutput=velocity*anyToMeters(1,distanceUnit)/anyToSeconds(1,timeUnit);
fprintf(formatFloat,velocity,distanceUnit,'per',timeUnit,' =',vOutput,'m/s');

Generated on Fri 07-Nov-2008 13:46:59 by m2html © 2005