Saturday, February 28, 2009

Moving to a new website

This website was intended to be a little collection of tips and tricks, but I haven't been able to update it as often as I originally intended to. Also, folks have been asking questions using the comment section, so now I have created a forum for math discussions on www.mathroot.com. It has a Matlab section but also a general math section, so if you have any questions, feel free to ask them there.

Saturday, July 14, 2007

An open-source alterntive to MATLAB

In case you do not have access to MATLAB (or if there aren't enough licenses to go around), you might want to try Octave which implements a lot of functions that are available in MATLAB, and maintains most of the syntax. The good part is that a lot of toolboxes that you have to pay extra for while purchasing MATLAB are implemented in Octave, so you could use them in Octave, or adapt them for your own use in MATLAB.

The bad part is that it's not graphical, and while you may not mind that for writing and running your programs, it's very hard to create and print plots. It's still a very useful program, so ahead and try it.

[Wikipedia page on Octave]

Thursday, May 12, 2005

Matlab toolbox for sigma-delta modulators

TIP: Richard Schreier's Matlab toolbox for the design and analysis of sigma-delta modulators can be downloaded for free from here. It works with R14 and higher.

If you ever work on the actual design of a sigma-delta modulator, this toolbox is immensely useful. It synthesizes the modulator given a noise transfer function, simulates the modulator for a given input, and also gives you realizable structures to implement the modulator. Plus a whole lot of other neat things. It comes with a very well-documented help file.

[from Anand Venkataraman]

Wednesday, May 04, 2005

The Matlab Programming Contest

The biannual Matlab programming contest starts Wednesday May 11. Here is the notification from Mathworks:

The next MATLAB Programming Contest will run from Wednesday May 11 at 9AM EST through Wednesday May 18 at 5PM EST. We will post the challenge and the rules at the start of the contest.

As in recent contests, there will be three stages: darkness, twilight, and daylight. During darkness, both the code and scores for all entries will be hidden. In twilight, the scores will be visible but the code will still be hidden. When daylight arrives, all scores and code are visible.

We'll also be awarding several mid-contest prizes, including MATLAB baseball caps, T-shirts, and jackets, so don't wait until the last minute to participate.

If you have any questions or comments about the contest, send e-mail to
contest@mathworks.com. We look forward to seeing your entry. Good luck!

http://www.mathworks.com/contest/

Tuesday, March 08, 2005

Profiling your MATLAB code

If you have complex code that's resource hungry, find the bottlenecks by profiling your code:
profile on
<run your script here>
profile off
profile report

[from Anand Venkataraman]

Friday, December 24, 2004

Saving data using string filenames in MATLAB

It is an easy matter to save data as a mat(MATLAB binary) file or an ASCII file so long as you know the filename beforehand. For ex: to save data in the variable datvar to a file mydata.dat, all you have to do is say
save mydata.dat datvar
However if you want to dynamically generate your filename, things get a little tricky since MATLAB's documentation is sparse about this. Here's how:
% Create a filename (myfile.001) using sprintf
fOut = sprintf('myfile.%03d',i);   % say, i=1

% save data as an ASCII file
save(fOut, 'datvar', '-ascii');

% Or, create a mat file - (myfile001.mat)
% since MATLAB binary files typically have the extension .mat
fOut = sprintf('myfile%03d.mat',i);   % say, i=1

% save data as matlab binary
save(fOut, 'datvar');

If you have multiple columns of data, just ensure that datvar is an array. Remember that the .mat file will retain the name of the variable datvar but the ASCII file will only contain data.

Wednesday, December 22, 2004

Creating movies in MATLAB

If you want to show how your plots change with time, a movie is a good idea. Especially since MATLAB can produce movies that can be embedded in your presentations, or be seen with any good ol' movie player. Here's how:

The idea is to create plot figures and compile them as frames of your movie.

% Create a new figure, and position it
    fig1 = figure;
    winsize = get(fig1,'Position');
    winsize(1:2) = [0 0];
% Create movie file with required parameters
    fps= 25;
    outfile = sprintf('%s',outFileName)
    mov = avifile(outfile,'fps',fps,'quality',100);
% Ensure each frame is of the same size
    set(fig1,'NextPlot','replacechildren');
    for i=1:numframes
        plot(x,y); % generate your plot
% put this plot in a movieframe
% In case plot title and axes area are needed
%     F = getframe(fig1,winsize);
% For clean plot without title and axes
        F = getframe;
        mov = addframe(mov,F);
    end
% save movie
    mov = close(mov);

Voila! (Make sure that you do not open any window over your plot window while MATLAB is compiling your movie, else those windows will become part of your movie)

Moving to a new website

This website was intended to be a little collection of tips and tricks, but I haven't been able to update it as often as I originally in...