Stuart’s MATLAB Videos

Watch and Learn

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!

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.