Doug's MATLAB Video Tutorials
August 16th, 2013
Plotting a matrix in MATLAB
Many times we use difficult syntax in MATLAB because we do not know there is a better way and do not know to look for a better way. A recently saw some MATLAB code that could have been a lot cleaner, so I made this quick video showing how to plot a matrix versus a vector instead of breaking the matrix into three different lines and then plotting.
August 9th, 2013
Customizing the color of an edit box in MATLAB
A MATLAB user recently asked me how the UI shown here (user story from Fulcrum Asset Management) was made. Those grey boxes are made from edit boxes that have been customized. This video shows how it is done.
July 23rd, 2013
Knowing when to optimize code in MATLAB
I work with a lot of recent computer science graduates who are learning MATLAB. Something I see from them is they often want to choose some complicated but fast algorithm to do a task I give to them in MATLAB class. Only after they spend a long time implementing and debugging this algorithm do they see that a really naive, simple implementation of the same algorithm is fast enough for the scale and scope of the work.
It is good to know how to write super-efficient algorithms, but it is even better to know if it is at all needed. There are two ways to think of speed: computation time and time to insight. We all know computation time is how long it takes to run the program. “Time to insight” is how long from when you start thinking about the program until you get an answer. If it takes me ten minutes to implement a slow version of an algorithm and I get my answer in one minute of calculation time, I am better off than the person who takes an hour to implement an algorithm that runs in 0.1 seconds. This is especially true if the problem only needs to be solved once.
In this example, I show how I throw together a proof of concept demo to find out if it even makes sense to try to make an efficient version of an algorithm. The answer will depend on size and scope of the problem, of course. It is the process that matters most.
July 18th, 2013
Working with dates in MATLAB
I am a little obsessive about data visualization. I have a side project selling a book I wrote. The data is not in a nice time history form, so I need to manually gather the data then reformat and interpolate the time data. This shows some basic date processing in MATLAB.
June 25th, 2013
I will be out for the next few weeks. While that is happening I wanted to point my newer readers with two of the “long series format” that I have done before. They are just as relevant today as they were then.
Volume Visualization in MATLAB
Managing your code in MATLAB
June 14th, 2013
I was asked recently how to generate all the combinations from two possible outcomes. It reminded me of a recent post on Flowing Data about the sum of two dice.
This is a nice little function, combvec, that not everyone knows about.
June 10th, 2013
Making a line visible over an image in MATLAB
It can be difficult to see a line that is drawn over an image. The line is often lost in the background colors. That is why cursors are colored as they are, so that they are visible on any background. I demonstrate some code that makes a line more visible with the same technique.
function h = cursorLine(x,y,innerThickness, outerThickness)
if nargin == 2
innerThickness = 2;
outerThickness = 4;
h.thick = line(x,y);
h.thin = line(x,y);
set(h.thick, 'color', [1 1 1]);
set(h.thin , 'color', [0 0 0]);
set(h.thick, 'linewidth', outerThickness);
set(h.thin , 'linewidth', innerThickness);
May 30th, 2013
Quick Tip: Speeding up debugging iterations
This week’s video is a quick tip to help speed up iterations when debugging MATLAB code. If your code requires user interactivity, such as selecting a file or folder from a dialog box, consider hardcoding a representative input value into your file while debugging. This eliminates for you to perform the interactive steps every time you run the code.
The video shows a couple of different approaches for switching between your debugging code and the code for the final version.
May 17th, 2013
Polar surface plot in MATLAB
MATLAB does not have a polar surface plot built in. You can use a normal surface plot if you convert your polar data into Cartesian with the pol2cart command.
We also cover how to get rid of the edges on dense surface plots like this one by setting ‘edgecolor’ to ‘none’.
May 3rd, 2013
Speeding up User Interfaces in MATLAB with profiler
Sometimes when you are working on a User Interface you want to use the profiler to speed up the code. However, with a UI so much time can be spent by the user rather than the code of interest that the timing is not as precise as would be preferred.
I like this technique so that I can do ad hock timings as needed in a complicated User Interface in MATLAB.