Triathlon Tools for MATLAB

Recently I got tired of continually writing the same equations at the MATLAB command prompt to convert my swim, bike, and run times into paces in the format we’re used to seeing. Temporarily putting aside my laziness, I wrote a handful of tiny helper functions to do the conversions and display them. Voilà, Triathlon tools for MATLAB (ver 1.0). In the ZIP-file you’ll find a bunch of basic functions:

  • Convert swimming times to 100m or 100 yard paces
  • Convert a running time to pace/mile or km
  • Compute cycling speeds from time and distance
  • Pretty-print the output of these functions
  • Convert running paces to treadmill speeds

Each one comes with help and examples. As you can see below, these pretty much dwarf the actual computation code.

function [m100, s100] = swimPace(distance, varargin)
%swimPace   Convert swimming lengths and times into 100 pace.
%   [M100, S100] = swimPace(DISTANCE, M, S) computes the "100 pace" (time
%   per 100 yards or meters) given a particular DISTANCE and the number of
%   minutes M and seconds S needed to swim it. M100 is the minutes part of
%   the 100 pace, and S100 is the seconds part. DISTANCE should be either
%   in yards or meters, and the pace will be in the same units.
%   [M100, S100] = swimPace(DISTANCE, TIMESTR) computes "100 pace" given a
%   DISTANCE and a string representing the time needed to swim it (for
%   example '5:18'). It is more natural to use this syntax to specify times
%   longer than one hour (for example, '1:10:37').
%   Examples
%   --------
%   % Example 1 - Pace for a 300 yard swim.
%   [m,s] = swimPace(300, 5, 10);
%   paceString(m, s, '100 yards')
%   % Example 2 - Michael Phelps's 400m IM world record time at the
%   % 2008 Olympic Games in Beijing, China.
%   [m,s] = swimPace(400, '4:03.84');
%   paceString(m, s, '100m')
%   See also bikePace, runPace, paceString.

% Copyright 2012 Jeff Mather
% This code is licensed under a Creative Commons "By Attribution" license
% (CC BY).  See for more details.

[m,s] = getTimeParts(varargin{:});

totalTime = m + s/60;
unitPace = totalTime / distance;

pace100 = 100 * unitPace;
m100 = floor(pace100);
s100 = (pace100 - m100) * 60;

By the way, here are the answers from MATLAB for the examples shown above.

ans =

1:43/100 yards

ans =


Happy swim/bike/running!

This entry was posted in Cycling, Fodder for Techno-weenies, MATLAB, Reluctant Triathlete, Running, Swimming. Bookmark the permalink.

3 Responses to Triathlon Tools for MATLAB

  1. scully says:

    what the hell is all that jargon up there?

  2. StephenS says:

    Jeff, this is awesome! Two questions: Is this the entire code, and can I steal it? This would be so much easier than using my Texas Instruments LED calculator from 1979.

  3. Jeff Mather says:

    Scully: That jargon is what I do all day at work. Or something like that.

    Stephen: You’re free to download, use, modify, and redistribute the code. The license just means that if you include it (or your own derivative of it) in any product, you need to credit me. And, yes, the ZIP-file contains all that you need . . . other than MATLAB. :^)

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>