Ken & Mike on the MATLAB Desktop

August 11th, 2008

Olympic fever

Watching the Olympics opening ceremonies, I’m reminded of my very first MATLAB program. I was a beleaguered freshman in a scientific computation class for which I did not meet the prerequisites. The first problem set was a warm-up to get used to doing assignments using MATLAB-files. To test our plot skills, the professor had us plot Olympic rings in a figure window.

It was an interesting challenge - learning trig functions, the subtleties of plot, and the twist of interlocking rings of different colors. Unfortunately, I did not start archiving my assignments until my sophomore year, so I don’t have that original M-file to share. Here is an unelegant, non-vectorized replica that I came up with today. I’m sure Loren could come up with something more clever, but it is a fun thing to do and in the spirit of the times.

five rings
%rings.m plots olympic rings
N = 100;
angle = linspace(pi/4,9*pi/4,N); %all the way around

% Make the x and y’s for each of the five circles
xb = cos(angle) * 0.9;
yb = sin(angle) * 0.9;

xy = cos(angle) * 0.9 + 1;
yy = sin(angle) * 0.9 - 1;

xk = cos(angle) * 0.9 + 2;
yk = sin(angle) * 0.9;

xg = cos(angle) * 0.9 + 3;
yg = sin(angle) * 0.9 - 1;

xr = cos(angle) * 0.9 + 4;
yr = sin(angle) * 0.9;

% Make the Figure
figure
hold on
plot(xb(1:3*N/4),yb(1:3*N/4),‘b’,‘linewidth’,10);
plot(xy(N/4:N),yy(N/4:N),‘y’,‘linewidth’,10)

plot(xk(1:3*N/4),yk(1:3*N/4),‘k’,‘linewidth’,10);
plot(xy(1:N/4),yy(1:N/4),‘y’,‘linewidth’,10);
plot(xb(3*N/4:end),yb(3*N/4:end),‘b’,‘linewidth’,10);

plot(xr(1:N/2),yr(1:N/2),‘r’,‘linewidth’,10);
plot(xg(1:N),yg(1:N),‘g’,‘linewidth’,10);

plot(xk(3*N/4:N),yk(3*N/4:N),‘k’,‘linewidth’,10);
plot(xr(N/2:N),yr(N/2:N),‘r’,‘linewidth’,10);

%make the axis pretty
axis equal
axis off
set(gca,‘XLim’,[-1.2 5.2])
set(gcf,‘Color’,[1 1 1])

What does this have to do with the desktop? Well, not much. I thought I’d come up with some gold-medal metaphor, but nothing uncontrived comes to mind. Instead I’ll leave you with a request for MATLAB programs analyzing olympic results, or even better, predicting olympic results. To get started, I recommend using urlread with an updated results site, such as: http://www.nbcolympics.com/medals/2008standings/index.html.

5 Responses to “Olympic fever”

  1. Ted replied on :

    Mike, I’ve been meaning to give published MATLAB scripts a try on blogs. My very first attempt (http://protomat.wordpress.com/) was in response to your Olympic fever. Even though I the blog portion for me wasn’t very successful, thanks much for the idea!

  2. Ken replied on :

    Fantastic! It’s great to see people using MATLAB publishing for their own blogs. Let us know what the stumbling blocks were in your usage so that we can improve the workflow.

    -Ken

  3. Ted replied on :

    I’m not sure what could be done better within MATLAB (glad to hear that?). The two blogging sites I’ve tried allow you to paste in HTML, but one changes the text (nix that one). In both cases I have to manually upload images and massage the HTML.

    What I’ve done before is post a published MATLAB tutorial on my personal website. I lose some interactivity that’s nice with blogs, but I don’t have to mess with the MATLAB report at all.

    Microsoft has a single web page format (.MHT). I wonder if this could be a possible workaround? Publish in MHT, copy and paste into the HTML field on the blogs. Do you think that has merit?

  4. Mike replied on :

    Ted,

    The problem with MHT (like so many interesting web solutions) is browser compatibility. As far as I understand it only IE supports them without a plugin. The other issue is worrying about RSS readers.

    For my solution, I have a modified form of publish which basically inlines the styles after publishing so I can just copy and paste the generated html in my blog. You can see an example of that above.

    I’ve also experimented with apache’s xml-rpc using MATLAB’s Java interface to upload a published M-file directly to a WordPress blog. That might make an interesting blog post.

    Thanks for taking me up on the challenge, I was impressed with your post!

  5. Mike replied on :

    Jiro just posted a nice example of a publishing + blog at the Pick of the Week blog.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Ken & Mike work on the MATLAB Desktop team.
  • DP: Hi i have a problem with ezplot3, i want to plot more than i curve in the same graph but hold on command...
  • Ken: Hi Arsalan, Unfortunately there is no way to get the new Editor API in older versions of MATLAB. -Ken
  • Arsalan: Hi, I am very excited about the MATLAB API for editor because right now i am working on a project and i need...
  • Johannes: Since I started using matlab-emacs some days ago I never experienced Emacslink. But I experienced some...
  • Francisco J. Beron-Vera: Hi all, I have recently learned about ViEmu (http://www.vimemu.c om) which, for Vi/Vim...
  • OysterEngineer: When I first learned of the Publish feature in MatLab, I thought it might be useful to help to...
  • Ken: Hi Herve, I’m not quite sure what you mean by “stand-alone&# 8221; mode? -Ken
  • Herve: I wonder when the publish fonction will be supported in standalone mode.
  • Mike: Ravi, What you described should work as far I understand it. Please follow up with technical support. With a...
  • Mike: @Daniel, Thanks for that note.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.