kennethkam.com

MATLAB Tricks

MATLAB has become part of my life recently. As I used it more often, I realised that there were a few things I needed to do that required scripting in MATLAB. For example, I wanted to create same-sized .eps figures for my research project, or be able to reorder the legend for graphs.

Creating same-sized figures

Visiting the MATLAB documentation solved my question.

set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperPosition', [0 0 4 2]);

PaperPosition follows this format:

[left bottom width height]

Finally, save the file as .eps:

print -despc output.eps

This can be repeated reliably, which will guarantee consistently-sized figures.

Reordering the legend

Visiting this forum thread helped.

% get the figure handle
h = 1 % or whatever fig
% get the axes handle
a = get(h, 'CurrentAxes')
% get the handles for children of the axes -- these are the data series handles
c = get(a, 'Children')
% generate a legend command using these "children"
legend(c([1 3 5]), 'label for data 1', 'label for 3', 'label for 5')

Remove all variables

Sometimes it is nice to remove all the variables using the command line:

clear all

Older Entries

A Simple Python GUI App

A big part of my internship at Airbus was to do with creating an application that would run on Windows. I remember dabbling in wxPython and matplotlib, and the end product was something that resembled a traditional desktop application. Whether it went to production or not, however, is a question that I probably will never be able to answer, but I diverge. I discovered that I can claim a bonus 5% in my design project if I did something ‘extra’. That something extra is a simple application that takes in a few inputs and outputs a graph.

Continue reading

Using MATLAB to Control Simulink

The final year of university is taking its toll on me. The act of balancing a research project, a team design project, several reports, numerous job applications, and MSc applications has took all my time away. Fortunately, there’s still a little glimmer of hope in all that work – in the form of MATLAB.

Continue reading

git and fabric

I have been a Subversion user for a while, and I wanted to learn another version control system. I chose git. From the start, I found converting to using git a pleasure. There are plenty of guides out there to get you started. In this entry, I will talk about how I used git to store my blog’s code. In addition, I will talk about fabric, an excellent automation tool for deploying your website to multiple servers, but works just as well if you are only doing it to one.

Continue reading

Furthering A Simple Django Blog

The last entry talked about using virtualenv, simple git commands, and a simple model and URLconf for the blog application. This entry will focus on Django contrib packages, which provide free RSS, a sitemap, generic comments, and many more.

Continue reading

A Simple Django Blog

I developed a simple Django application that powers kennethkam.com. This entry will describe the workflow I used, from using git as my repository, using fabric for deployment, and various Django apps that can be used to plug straight into your project. This first entry will focus on using virtualenv, git, and knocking up a simple blog while the second one will focus on Django contrib packages, more git topics, and Fabric.

Continue reading

Django Powered

Welcome to my humble blog. If I recall correctly, this is my fifth attempt at writing a blog. The first blog was powered by WordPress and it was laden with teenage angst; the second one was also powered by WordPress, but I fail to recall what I wrote about; the third one was also powered by WordPress, and the topic was more football than teenage angst. The last blog aimed at documenting my internship at Airbus UK, but feeble efforts resulted in sporadic entries, which resulted in a blog that didn’t have much to offer.

Continue reading