Cris’ Image Analysis Blog

theory, methods, algorithms, applications

Some assorted MATLAB functions

Here I collect some old functions I wrote for MATLAB and still find useful at times.

For all the functions below, the licensing is simple: do whatever you want with the code, but don’t blame me if anything goes wrong.


percentile — Percentile value of input array. Missing from the MATLAB toolbox (the statistics toolbox has `prctile`). I copied median and modified it a bit, so it’s mostly code by The MathWorks.

student_t — Returns the right-critical value of the Student distribution for a=0.025 and any number of degrees of freedom. Use this to compute the 95% confidence interval of the mean of a set of samples, as done by confidenceinterval (below).

confidenceinterval — Returns the right-critical value for the 95% confidence interval of the location of the mean of a set of samples (requires student_t, above).


prettyplot — Prettier linear plot. Works just like plot, but avoids the line and markers being on top of each other. Instead, the line joins the markers without touching them.

boxplot — Elegant box plot, looks a lot better than what MATLAB’s own `boxplot` command produces (in its statistics toolbox). Plots grouped data as a box with whiskers, indicating min, 25th percentile, median, 75th percentile, and max. Optionally plots outliers (points outside of 1.5 IQR) as dots.

movelegend — Moves the legend of an axes to one of the positions defined in legend. legend doesn’t allow to move the legend once it’s created, so here you have. [This is really old, I don’t know if it still works with the new graphics engine.]


np2 — Next higher power of 2. np2 is the same as nextpow2, except that it can work on arrays.

cell2str — Convert cell array into evaluable string. This one is missing in the MATLAB toolbox. Similar to mat2str. It should be possible to rename this as @cell/mat2str.m.

mvfield — Rename structure field. This one is also missing in the MATLAB toolbox. Goes well together with rmfield.