MatlabCommands

From University of Washington - Ubicomp Research Page
Revision as of 20:14, 22 February 2007 by Jonathan Lester (talk | contribs)
Jump to navigationJump to search

Overview

Some useful Matlab commands

Printing Progress bars

If we want to print a progress display (i.e. 0 to 100% of completion and we know how many iterations there are we use the following code to do the printing of the dots for us. Of course if you use fprintf inside the loop this doens't work so well.

<matlab>printDelay = 46/outputDuration; printCounter = 0; fprintf( 'Writing frames\n' ); fprintf( ' 0%% 20%% 40%% 60%% 80%% 100%%\n' ); fprintf( ' | | | | | |\n' ); fprintf( ' ' );

while(x)

   printCounter = printCounter + printDelay;
   while( printCounter >= 0.00001 )    printCounter = printCounter - 1;    fprintf( '.' ); end         

end </matlab>


Unix Timestamps

    The unix timestamps used in uwar files are counting the number of milliseconds since the 1/1/1970 epoch. So if we're given the timestamp 1171308738000, this corresponds to 12-Feb-2007 12:32:18.
    • to get a normal unix timestamp we need to divide by /1000.
      • 1171308738000/1000 = 1171308738 (Mon, 12 Feb 2007 19:32:18 GMT)
    • To convert this to a Matlab time (where 1.0 = 1 day since the 1/1/000 epoch), we need to convert the timestamp into days and add in the 1/1/1970 epoch offset, we use -7 to conver the data to the PST timezone
      • 1171308738000/1000/(24*60*60) + datenum( 1970,1,1,-7,0,0 ) = 733085.522430556 (12-Feb-2007 12:32:18)