This is a collection of functions of general usefulness or importance for Matlab programming. There are two groups of files:
-
utility files - stored in the
util
directory - that I have created to fill holes in the standard Matlab library over the years. -
structure extensions extend the Matlab struct class with several methods that anyone would be happy to have. For the most part, these tools are intended to make structures be more database-like, so some of them may be outmoded by Matlab's new data types. These have two subtypes:
- methods, stored in the
util/@struct
directory - tools, stored in the
util
directory.
- methods, stored in the
To "install," simply add the util
directory to your Matlab path.
Currently includes the following:
approx.m
-- Tests whether numbers are approximately equal, to a user-specified tolerancebisect_find.m
-- Bisection search in a sorted cell array of stringscapitalize.m
-- Capitalize the first letters of words in "titlecase"ccrop.m
-- Crop trailing all-NaN rows and columns from a cell arraycisnan.m
-- Return a logical array indicating NaNs in a cell arrayifinput.m
-- Request user input with a pre-set default valueifnum2str.m
-- num2str, but don't error if input is already a strifstr2num.m
-- str2num, but don't error if input is already a numstrdist.m
-- Naive string distance algorithmstrnearest.m
-- Slightly more clever string distance algorithmtr.m
-- analog to tr(1), translate input characters to output charactersuniques.m
-- return a list of unique values sorted to match their original order of appearance
Methods
(in util/@struct
)
concat.m
-- Concatenates the contents of two or more fieldseq.m
-- Recursively test if structures are equalexpand.m
-- Duplicates records in a structure array according to a delimited fieldfieldop.m
-- Performs an operation on the fields of each record in a structure arrayfilter.m
-- Finds records in a structure matching a set of criteria; analogous to SQL WHERE clauseifrmfield.m
-- rmfield, but don't error if the field doesn't existlookup.m
-- Given an entry in column A, find the corresponding entry in column Bmoddata.m
-- Modify the contents of a given field in a structure arraymvfield.m
-- Rename a field without changing its position in the field orderpivot.m
-- Draw an Excel-style "pivot table" to specselect.m
-- Pick out named fields; analogous to SQL SELECT clauseshow.m
-- Pretty-print structures. A MONSTER function.sort.m
-- I was shocked I had to write this myself.stack.m
-- Creates a union of fields of two input structuresstruct2xls.m
-- Write a structure to an Excel worksheet (requires MS Office)top.m
-- Show the top n records according to a given fieldtrunc.m
-- Truncate a structure after n records
Utilities
(in util
)
read_dat.m
-- Read delimited data into a struct (my own implementation, works better for me thancsvread
)vlookup.m
-- Lookup the contents of one field in another structure; add another field to the first structure. Kind of like an SQL JOIN.accum.m
-- Analogous to SQL GROUP BY, but with some neat tricks.xls2struct.m
-- Convert an Excel worksheet into a struct.