- Use shortcuts on desktop 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:
- Dock windows in the desktop 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.
- Make throw-away scripts 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
- Use F5 to save and run The script I mentioned above is a lot easier to iterate on if you just hit F5 to save and run.
- Use run configurations You can click the down arrow on the right side of this button
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
Opens the current directory in Windows
clear clc close all
Changes directory to a common destination
Make all future figure windows start docked
Make all future figure windows start normally
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.
clear clc close all
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!
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.