Doug's MATLAB Video Tutorials

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.

April 17th, 2013

Generalizing the access to an array of structures in MATLAB

Recently a MATLAB user asked me how to make it possible to work with an array of structures in such a way that she could filter the array of structures and then combine the remaining fields. Once combined she would run arbitrary processing functions on this combined data.

This generalized architecture allows her to not use switch case and other flow control. The strings that represent the fields of interest could come from a GUI making her GUI able to process in many arbitrary and customizable ways.

Here is the code from the post:
clear
clc

s(1).condition = 1;
s(2).condition = 1;
s(3).condition = 2;
s(4).condition = 2;

s(1).velocity = [11:21];
s(2).velocity = [22:32];
s(3).velocity = [33:43];
s(4).velocity = [44:54];

s(1).acceleration = [111:121];
s(2).acceleration = [122:132];
s(3).acceleration = [133:143];
s(4).acceleration = [144:154];

fieldToFilterBy    = 'condition';
valueToFilterBy    = 2;
fieldToProcess     = 'acceleration';
processingFunction = @mean;


listOfFilterValues    = [s.(fieldToFilterBy)];
vi                    = (listOfFilterValues == valueToFilterBy)
filteredStructure     = s(vi)
mergedFieldOfInterest = [filteredStructure(:).(fieldToProcess)]
processedFilteredData = feval(processingFunction, mergedFieldOfInterest)

April 8th, 2013

Using ‘dbstop if error’ and conditional breakpoints to debug MATLAB

Sometimes MATLAB throws an error, but because the error is inside of a function you can not see what caused this error. By telling the debugger to stop execution under certain conditions or right before an error is thrown you will be better able to understand the conditions that caused the error.

March 25th, 2013

Using otherwise to throw errors in a switch case

In some code there is an enumerated set of choices. People will use a switch case statement to check for all but one choice and then catch that last one in the ‘otherwise’ block of their code. However, if there is unexpected inputs, the ‘otherwise’ will fire when it should not.

This video shows a technique for catching this problem. It is important to catch these errors from unexpected inputs immediately, because they can have effects on your code much farther down the line. When this happens, it would be hard to trace back to the cause.

March 14th, 2013

Persistent variables in MATLAB

There are situations where you want MATLAB to remember the value of a variable from one call of a function to another call of that function. We show to use a persistent value to accomplish this. This approach is convenient when calling the same function from several different places, or in callbacks, such as when coding an app or a timer.

March 5th, 2013

Adding UICONTROLS to MATLAB without GUIDE for simple interactive figures

There are often small tweaks to functionality that you would like for a figure in MATLAB. This video shows how to add a button to a figure that will allow you to toggle the units of a y axes between inches and centimeters.

February 20th, 2013

Simple visualizations for a statics problem in MATLAB

A colleague was trying to draw some structures and do basic static analysis on them. He wanted to write a routine that would draw a pinned beam given the locations of the two pins. This can be done pretty easily in MATLAB with a patch. This video shows how to do that. It also discusses strategies such as not using ‘Magic Numbers’ in your code.

February 13th, 2013

GUI building in MATLAB

This post is a continuation of the last video where we built a simple GUI in MATLAB. This continues by showing how to run initiation code for a MATLAB GUI and explains what the handles structure is.

February 6th, 2013

Introduction to GUI building with GUIDE in MATLAB

As we approach video number three hundred on this blog, I thought it was time to remake the original video that got this all started. I still refer people to it on a weekly basis. This shows you how to make a simple GUI in MATLAB.

The basics of GUIDE are:

  • Lay out controls of the GUI
  • Wire up callbacks, the function that runs when you interact with the controls
  • Gather data from the controls

This series shows these basic skills. They allow you to make a wide array of GUIs very easily.


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

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