Share your favorite snippet or utility

Matt Fig on 20 Sep 2012
Latest activity Reply by DGM on 23 Feb 2023

I am wondering what others use for those little short-cuts or niceties in MATLAB. I have in mind something you wrote or something somebody else wrote or an underused MW function.
Here are my two favorites.
This is a simple script I use. Here is the entire contents of CLC.m (yes, it is capitalized):
clear all,close all,clc
Very simple, but I use it all the time. Here is another one I use so often that I forget not every machine has it (though every machine should, IMO):
Here is an underused MW function that I occasionally employ when working on someone else's machine. The usual response is, "Wait, what did you just do?"
home
What are some of yours?
DGM
DGM on 23 Feb 2023
For some reason, I can never remember the name of the lookfor() function, and looking for the lookfor() function is a pain when you don't know what it's called.
So I just called it what I expected it to be called
apropos 'modified bessel'
besseli - Modified Bessel function of first kind besselk - Modified Bessel function of second kind besseli - Modified Bessel function of the first kind for symbolic expressions besselk - Modified Bessel function of the second kind for symbolic expressions
Darik
Darik on 21 Sep 2012
I'm a clumsy typist...
function hepl (x)
help (x)
end
Sean de Wolski
Sean de Wolski on 21 Sep 2012
Tyop corrections in R2012b!!
hepl fmincon
Undefined function 'hepl' for input arguments of type 'char'.
Did you mean:
>> help fmincon
I already highlighted this as my second favorite new feature:
Matt Fig
Matt Fig on 21 Sep 2012
@Sean, I have only the command window and a minimized command history open to the left of that space. No docked anything. I am old-school. That is why I like whats so much, one simple command and I can do it all and I don't have to keep any more panels open all the time. Let me know "what" you think if you try it.
Image Analyst
Image Analyst on 21 Sep 2012
Is there any way to make a shortcut button called something like "Format Code" which essentially does Control-A (to select all the text in the editor window) followed by Control-I (to fix up the indenting/alignment)? That's a nice set of utility commands that I use often.
Image Analyst
Image Analyst on 21 Sep 2012
Thanks - it works!
Sean de Wolski
Sean de Wolski on 21 Sep 2012
This should be it's own question because I want 4 points :)
smartIndentContents(matlab.desktop.editor.getActive)
Sean de Wolski
Sean de Wolski on 21 Sep 2012
@Matt, do you not keep the current directory panel open? I might have to give whats a try if it means I could close that panel.
Shane
Shane on 21 Sep 2012
I use uigetfile and uigetdir day in and day out, so when I am writing a new code I always add this code to the beginning of my function and I love it:
if isappdata(0,'previousDirectory')
startDirectory=getappdata(0,'previousDirectory');
if isnumeric(startDirectory)
startDirectory='C:\';
end
else
startDirectory='C:\';
end
[uigf1 uigf2]=uigetfile('*.bdf','SelectFile to Load',startDirectory);
setappdata(0,'previousDirectory',uigf2);
Simply saves my directory location so that I dont start at C:\MyDocuments|MATLAB every time.
Robert Cumming
Robert Cumming on 21 Sep 2012
Downloaded whats for the first time - very handy! :)
Srinivas
Srinivas on 20 Sep 2012
I have a lazy shortcut to open the current folder I am working in
system(strcat('%SystemRoot%\explorer.exe',' "',pwd,'"'));
:)
Ashish Uthama
Ashish Uthama on 21 Sep 2012
winopen .
:)
Jan
Jan on 20 Sep 2012
Even "%SystemRoot%\explorer.exe" will work under Windows only, Sean.
Robert Cumming
Robert Cumming on 20 Sep 2012
I second home - its very useful, the number of times I've had to go to a colleagues screen to help them debug and they have typed clc thinking they are helping me start - but of course that clears the error and any messages on the screen....
My favourite - its not a snippet but a code I would struggle to do wihtout since I work on multiple project is my SaveEditorHistory FEX.
Daniel Shub
Daniel Shub on 20 Sep 2012
@Sean, I cannot get dbquit to be recursive, but adding the following makes it so calling it twice works
if feature('IsDebugMode')
disp('MATLAB was in debug mode, cll must be run a second time.')
dbquit('all');
end