Doug's MATLAB Video Tutorials

July 20th, 2011

Managing code in MATLAB: Functions of variable numbers of inputs and outputs

This is the first series of MATLAB video tutorials that are an attempt to systematically make videos for a “technology trees” for using MATLAB. This first tree covers the various kinds of MATLAB files you might write. The tree shows you the order you should watch them because some rely on skills you need to learn from earlier videos, but some do not.

Script Function 1in1out MinNout VarArg Cell mode Markup Interactive Driver script Sub function Nested

This video will allow you to do input parsing so that you have the ability to overload functions, meaning allow them to react differently to different inputs.

July 8th, 2011

Managing code in MATLAB: Functions of multiple inputs and outputs

This is the first series of MATLAB video tutorials that are an attempt to systematically make videos for a “technology trees” for using MATLAB. This first tree covers the various kinds of MATLAB files you might write. The tree shows you the order you should watch them because some rely on skills you need to learn from earlier videos, but some do not.

Script Function 1in1out MinNout VarArg Cell mode Markup Interactive Driver script Sub function Nested

This video will modify the function to accept more inputs and give more outputs.

June 27th, 2011

Managing code in MATLAB: Functions of one input and one output

This is the first series of MATLAB video tutorials that are an attempt to systematically make videos for a “technology trees” for using MATLAB. This first tree covers the various kinds of MATLAB files you might write. The tree shows you the order you should watch them because some rely on skills you need to learn from earlier videos, but some do not.

Script Function 1in1out MinNout VarArg Cell mode Markup Interactive Driver script Sub function Nested

This video will make a function of one input and one output that we will modify through much of the rest of the tree.

June 20th, 2011

Managing code in MATLAB: Functions

This is the first series of MATLAB video tutorials that are an attempt to systematically make videos for a “technology trees” for using MATLAB. This first tree covers the various kinds of MATLAB files you might write. The tree shows you the order you should watch them because some rely on skills you need to learn from earlier videos, but some do not.

Script Function 1in1out MinNout VarArg Cell mode Markup Interactive Driver script Sub function Nested

This video will make a simple function, then the next video will make a different function of one input and one output that we will modify through much of the rest of the tree.

June 13th, 2011

Managing code in MATLAB: Scripts

This is the first series of MATLAB video tutorials that are an attempt to systematically make videos for a “technology trees” for using MATLAB. This first tree covers the various kinds of MATLAB files you might write. The tree shows you the order you should watch them because some rely on skills you need to learn from earlier videos, but some do not.

Script Function 1in1out MinNout VarArg Cell mode Markup Interactive Driver script Sub function Nested

You can see that understanding what a script is in MATLAB is the fundamental skill needed to understand functions, subfunctions, etc…

This video will show how and why you write script files in MATLAB.

Stuart did a video that covers this material in a similar but different way.

June 3rd, 2011

Inserting data into a vector in MATLAB

If you want to insert a data point into an existing series, you may need to insert a corresponding data point in another vector in the same place. You could do that with logical indexing and concatenation of vectors as shown in this video.

May 27th, 2011

Top five productivity practices in MATLAB

I teach the “MATLAB 101″ course for all of our new technical support engineers at MathWorks. When I come to their computers, I become aware of little tweaks I have made to my working style and MATLAB environment that save me steps, or a few seconds HUNDREDS of times a day. Here are five tips that you can implement right now to make things better for you.
  1. Use shortcuts on desktop
  2. You can add custom shortcuts to the MATLAB desktop to get single-click access to any MATLAB code you run often. I see so many people that leave their MATLAB desktop with just the default shortcuts: noshortcuts.jpg

    I made the following shortcuts by just dragging code from the command window or editor directly to the shortcut bar. You can learn more about making shortcuts here. Here are the shortcuts I find myself using all of the time:

    Gets MATLAB back into a fresh state

    clear
    clc
    close all
    
    Opens the current directory in Windows
    winopen(pwd)
    
    
    Changes directory to a common destination
    cd('C:\Users\dhull\Desktop')
    
    Make all future figure windows start docked
    set(0,'DefaultFigureWindowStyle','docked');
    Make all future figure windows start normally
    set(0,'DefaultFigureWindowStyle','undocked');
  3. Dock windows in the desktop
  4. I see so many people spend a few seconds hunting for the editor, figure windows, etc *every* time they switch contexts. This is so easily avoided, just put MATLAB full screen, dock the desktop components if they aren’t already docked (using the little arrow in the upper right corner of each component)  and rearrange the desktop components until you can see everything at once.
  5. Make throw-away scripts
  6. MATLAB is great because you can use it interactively. However, I see people too often do everything at the command line and forget how they got to whatever state they end up in. They then need to dig around the command history looking for the specific commands they used that worked. If you work in a script, and just keep modifying it as you go, you know exactly how you got to the state you finish in. I also recommend starting the script with
    clear
    clc
    close all
    
    so that you always start in a known state.  One small gotcha – if you are using the debugger, don’t include the clear command at the beginning of your script.  It will clear your debugger breakpoints in addition to clearing your workspace variables.
  7. Use F5 to save and run
  8. The script I mentioned above is a lot easier to iterate on if you just hit F5 to save and run.
  9. Use run configurations
  10. You can click the down arrow on the right side of this button

    runconfig.jpg

    to see a script that you can run when you hit F5. This is an advanced form of the above tip. It allows you to specify a script to run when you hit F5. This is often used to set up the environment for a function that you are working on.

    These five tips will save you a few seconds each, hundreds of times a day. They will make MATLAB programming much faster and keep you in the flow!

May 16th, 2011

Using logical indexing to plot points meeting a specific criteria only.

If you have a vector of coordinate for a set of points, you might want to differentiate those points. To do that a concept called logical indexing will help you pull out a subset of those points easily.

Here is a quick example (See the second video for more details)


>> L = logical([0 1 0 1])

L =

     0     1     0     1

>> a = [1 2 3 4]

a =

     1     2     3     4

>> a(L)

ans =

     2     4

The above video made practical use of logical indexing. The video below shows logical indexing in a more academic treatment.

May 9th, 2011

Using image to view data instead of surf and view(2).

This video outlines a common error made with MATLAB, and how to avoid it. Often people will use the programming pattern of: surf(Z); view(2) This really does something very similar to: imagesc(Z)

April 29th, 2011

Sudoku solver in MATLAB by webcam

From our Japan office via Steve’s blog:

This just tickles my fancy, and I think everyone should watch it.


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 The MathWorks.