Posting MATLAB Code on WordPress.com


Until recently whenever I wanted to post some code on my wordpress blog I used to put something like this

  
function m = magicsquare(n)
%MAGICSQUARE generates a magic square matrix of the size specified
%    by the input parameter n.

% Copyright 2003-2006 The MathWorks, Inc.

if ischar(n)
    n=str2num(n);
end
m = magic(n); 

Which is actually not bad at all. But what if I wanted it with syntax highlights for a specific language, say C++, Java, or why not MATLAB as well. And on top of that, that you could get line numbering, line highlighting, no column wrapping, and a bunch of other cool ways to display code. Well the guys at wordpress came up with a nice way to do it:

We have created a shortcode you can wrap around source code that preserves its formatting and even provides syntax highlighting for certain languages […] To accomplish the above, just wrap your code in these tags:

[sourcecode language=”css”]
your code here
[/sourcecode]

via Posting Source Code — Support — WordPress.com.

So if I input something like this:

[sourcecode language="matlab"]
function m = magicsquare(n)
%MAGICSQUARE generates a magic square matrix of the size specified
%    by the input parameter n.

% Copyright 2003-2006 The MathWorks, Inc.

if ischar(n)
    n=str2num(n);
end
m = magic(n);

[/sourcecode]

I actually get this:

function m = magicsquare(n)
%MAGICSQUARE generates a magic square matrix of the size specified
%    by the input parameter n.

% Copyright 2003-2006 The MathWorks, Inc.

if ischar(n)
    n=str2num(n);
end
m = magic(n);

Pretty neat! There are a lot of options for the shortcode check the link to see them.

Advertisements

9 thoughts on “Posting MATLAB Code on WordPress.com

  1. Pingback: Legendre polynomials in MatLab | Room 196, Hilbert's Hotel

  2. Pingback: Matlab em wordpress | Pedro Dreyer

  3. Pingback: Using MATLAB codes | hiepvudang

If you liked this post please leave a comment or consider subscribing.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s