What non-built-in functions do you use frequently?

9 views (last 30 days)
A handful of homemade functions in my filepath get used at least weekly. Not all of them are beautifully written or impressive in any way, but they simply solve little recurring problems. Of the scripts like this that I've written for myself I've often thought, "why didn't I write this years ago?"
Do you frequently use any non-specialized functions that solve problems big or small?

Answers (3)

Image Analyst
Image Analyst on 15 Dec 2014
I use John D'Errico's allwords() and polyfitn() quite a bit. I also use Yair Altman's MaximizeFigureWindow code (attached and updated for R2014b and earlier). And of course export_fig() like almost everyone else.
I use xlswrite1 by By Matt Swartz to write to Excel, along with a class I wrote that does a ton of various Excel operations via ActiveX, like formatting borders, numbers, sizes/widths, etc.
I use little utilities I wrote to warn/alert/notify the user modally, get number of bits, get a folder for custom settings for my app (because Windows doesn't allow anything under the Program Files folder where my apps get installed), and get the executable folder of a compiled application (all attached). I also use my function to extract the N largest (or smallest) blobs from a binary image quite a bit because there's nothing built in to the Image Processing Toolbox to do that conveniently.
I also maintain an m-file that's nothing but random, assorted, commonly used snippets, called common_code.m. I often pull snippets from there when I build the demos I upload here.
  1 Comment
Chad Greene
Chad Greene on 15 Dec 2014
Oh, I like allwords. I had not seen that before.
At first I thought, MaximizeFigureWindow sure is a mixed-case mouthful for a simple task compared to my fullfig, which does more for less. Then I read Yair's well-written description of MaximizeFigureWindow. Now I see the reason for the Java solution.
And yes, export_fig and polyfitn. Sometimes I forget they aren't built-in functions.

Sign in to comment.


Sean de Wolski
Sean de Wolski on 15 Dec 2014
Edited: Sean de Wolski on 15 Dec 2014
The one I've been using a ton recently:
function mkcd(dirname)
% Make directory and navigate to it
% See Also: mkdir, cd
% One input expected, must be row string
narginchk(1,1)
validateattributes(dirname,{'char'},{'row'})
% Engine
mkdir(dirname)
cd(dirname)
end
  2 Comments
Sean de Wolski
Sean de Wolski on 15 Dec 2014
Edited: Sean de Wolski on 15 Dec 2014
I've actually upped the quality of cll. It's now this:
evalin('base','clear')
close all force
clc
try
delete(findall(allchild(0)));
end
try
dbquit('all');
end
% Sean de Wolski
% Copyright 2014 The MathWorks, Inc.
% Kill the try/catch warning
%#ok<*TRYNC>

Sign in to comment.


DGM
DGM on 3 Aug 2022
Edited: DGM on 3 Aug 2022
I know nobody needs a thread revival, but it's something that I'm constantly reminded of because I have to avoid it in posting things on the forum. I use MIMT imrange() all the time for fetching the global extrema of arrays. It's such a ridiculously simple and obvious convenience that losing it drives me bananas.
A = imread('cameraman.tif');
rg = imrange(A)
rg =
7 253
[mn mx] = imrange(A)
mn =
7
mx =
253
There are tons of things in MIMT that I think would qualify, but imrange() is the most simple, general, and frequent.
On the other hand, the most common non-TMW tool I use when on the forum is when(). Not that I use it super frequently, but I suppose If one needs to know the results of when(), one might need something like Rik's ifversion().
  2 Comments
DGM
DGM on 3 Aug 2022
The difference is that imrange() predates bounds(), and until you mentioned it, I had no idea that it existed (learn something new every day). I often prefer to have the output as a 2-element vector, so doing the same with bounds() isn't really much more convenient than using max() and min().
That was a bad example on my part. The result isn't like getrangefromclass(). It's the actual array extrema independent of the class. Maybe I should pick a different image for clarity.

Sign in to comment.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by