|
1 | 1 | # MATLAB Fun Utils |
2 | 2 |
|
3 | | -Functional programming-inspired utility functions for MATLAB. |
| 3 | +Functional programming-inspired utility functions for MATLAB. Puts some fun into |
| 4 | +using MATLAB :-) |
4 | 5 |
|
5 | 6 |
|
| 7 | +## Motivation |
| 8 | + |
| 9 | +For some non-vectorizable operations, it's nicer if you can write a one-liner |
| 10 | +using anonymous function syntax, instead of writing yet another `for` loop. The |
| 11 | +utility functions in this library provide such functionality. |
| 12 | + |
| 13 | +Note that MATLAB already provides some similar functionality with its `arrayfun` |
| 14 | +and `cellfun` functions. Do check those functions out, too, if you aren't |
| 15 | +familiar with them. |
| 16 | + |
| 17 | + |
| 18 | +## Requirements |
| 19 | + |
| 20 | +Should work in any recent version of MATLAB (say, R2012a or higher). Thus far, |
| 21 | +only tested on R2014b. |
| 22 | + |
| 23 | + |
| 24 | +## Package contents |
| 25 | + |
| 26 | +Note: each function is documented. Use `help <function name>` or `doc <function |
| 27 | +name>` to read the documentation. |
| 28 | + |
| 29 | +Unit tests are also included. Execute `runtests tests` in the root folder to |
| 30 | +run them, using MATLAB's built-in Unit Testing framework. |
| 31 | + |
| 32 | + |
| 33 | +### cmap |
| 34 | + |
| 35 | +A basic implementation of a generic `map` function for processing items in a |
| 36 | +collection, whether it's a numeric vector, a matrix with rows or columns, a cell |
| 37 | +array, or a struct array. |
| 38 | + |
| 39 | +Supports parallel processing (pass in the `useParallel` flag). |
| 40 | + |
| 41 | + |
| 42 | +### cfilter |
| 43 | + |
| 44 | +Basic `filter` function for filtering items in a collection. |
| 45 | + |
| 46 | + |
| 47 | +### mapfiles |
| 48 | + |
| 49 | +Alternative to MATLAB's `dir` function. Compare: |
| 50 | + |
| 51 | + files = dir('/my/path/*.png'); |
| 52 | + images = cell(size(files)); |
| 53 | + for i = 1:length(files) |
| 54 | + images{i} = imread(fullfile('/my/path', files(i).name)); |
| 55 | + end |
| 56 | + |
| 57 | +...with: |
| 58 | + |
| 59 | + images = mapfiles('/my/path/*.png', @(f) imread(f)); |
| 60 | + |
| 61 | +Also includes support for recursive listing, and basic filtering (files only, |
| 62 | +directories only, exclude hidden files). |
| 63 | + |
| 64 | + |
| 65 | +### mapsubplots |
| 66 | + |
| 67 | +Easily create a plot with subplots: |
| 68 | + |
| 69 | + mapsubplots(4, @(i) plot(i.*rand(100,1), '-'), 'title', 'Plot %d'); |
| 70 | + |
| 71 | + |
| 72 | +### explorecell |
| 73 | + |
| 74 | +A small graphical user interface for exploring the contents of a cell array. Try |
| 75 | +this, for example: |
| 76 | + |
| 77 | + % Read a bunch of images. |
| 78 | + myCell = cmap({'peppers.png', 'fabric.png', 'football.jpg'}, @(f) imread(f)); |
| 79 | + |
| 80 | + % Open the Cell Explorer to view all the images. |
| 81 | + explorecell(myCell, @(ax,item,idx) imshow(item, 'parent', ax)); |
| 82 | + |
0 commit comments