Posts Tagged ‘matlab’

Create a dated log file in Matlab

Posted in Uncategorized on July 23rd, 2009 by Michael Ewens – Be the first to comment

If you change your datasets or code a lot in Matlab, it is smart to keep track of the results over time (trust me….). The ‘diary’ function allows you to record all output of your scripts to a file. Append your main .m file with the following code to create a diary/log file that is uniquely dated to the time (to the minute) that you ran the script:

date_now = clock;
date_now = strcat(num2str(date_now(1)),'_',num2str(date_now(2)),'_', num2str(date_now(3)), num2str(date_now(4)), num2str(date_now(5)));
diary(strcat('log', date_now,'.log'));

Inline Matlab Code in Latex

Posted in Reading on April 26th, 2009 by Michael Ewens – Be the first to comment

http://bennewhouse.com/blog/?p=3

Simple Bootstrap Sample in Matlab

Posted in code on March 25th, 2009 by Michael Ewens – 1 Comment

Let x be your vector of data which has to be bootstrapped. For each instance of the loop write:

x = x(floor(rows(x)*rand(rows(x),1))+1,:); % bootstrap observations

Now we have a matrix with the same number of rows and columns, but with re-sampled data with replacement. A one line bootstrap! (Modified code from John Cochrane)

Using Remote Files in Matlab

Posted in code on March 24th, 2009 by Michael Ewens – Be the first to comment

If you have an FTP server set-up somewhere with ample space and bandwidth, Matlab can store and retrieve its files and data remotely. Just use these simple commands to connect and disconnect:

% File to connect to the server where my Matlab/data resides

% connect to the db
f = ftp('yourdomain.com', 'user', 'password');

% change the directory
cd(f, 'matlab');

% now change the directory that we want to download the directory
cd '/';

% Download the directory
mget(f, 'remote_dir');

% *****************
% INSERT PROGRAM HERE
% *****************

% when done move a directory here
cd ..
% now move the directory back to the server
mput(f, 'remote_dir');
disp('Files have been put back on the server');

% close the connect
close(f);