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

2 ビュー (過去 30 日間)
Chad Greene
Chad Greene 2014 年 12 月 15 日
編集済み: DGM 2022 年 8 月 3 日
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?

回答 (3 件)

Image Analyst
Image Analyst 2014 年 12 月 15 日
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 件のコメント
Chad Greene
Chad Greene 2014 年 12 月 15 日
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.

サインインしてコメントする。


Sean de Wolski
Sean de Wolski 2014 年 12 月 15 日
編集済み: Sean de Wolski 2014 年 12 月 15 日
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 件のコメント
Chad Greene
Chad Greene 2014 年 12 月 15 日
Ah, that's a great thread; thanks for the link. From that thread I'm reminded that
close all; clear [all or some variant]; clc
seems to be a common command line shortcut that tends to spark debate.
I like your Sean function :)
Sean de Wolski
Sean de Wolski 2014 年 12 月 15 日
編集済み: Sean de Wolski 2014 年 12 月 15 日
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>

サインインしてコメントする。


DGM
DGM 2022 年 8 月 3 日
編集済み: DGM 2022 年 8 月 3 日
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 件のコメント
Walter Roberson
Walter Roberson 2022 年 8 月 3 日
Is there a difference between imrange and bounds ?
Or does imrange returned the defined value range for that class of data? Like [0 1] for isfloat, and intmin and intmax for integer types ?
DGM
DGM 2022 年 8 月 3 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by