Category: Matlab examples
-
Coarse-grained parallelism in Matlab with parfor
Previously, I discussed how you can take advantage of multiple cores in C. In day-to-day research, however, it’s more common to work with high-level languages like Matlab and Python. Although Matlab has been multithreaded for several years now, it’s not very good at maximally using all the cores in a computer. You can verify this…
-
Obscure Matlab features #2: linear indexing, sub2ind, ind2sub
Matlab supports 3 forms of indexing matrices. There is the familiar range indexing that selects a submatrix within a larger matrix: This is also called sub-indexing. There is also logical indexing: These two methods are fairly expressive, yet there are a certain number of operations which are awkward or impossible to perform with these. Let’s…
-
An alternative method for spike-triggered covariance
Spike-triggered covariance (STC) is a method of estimating receptive fields with quadratic or more generally symmetric nonlinearities in stimulus space. The basis idea behind spike-triggered covariance is that the ensemble of stimuli which drive a cell has different statistical properties than the ensemble of all stimuli that are presented to a neuron. In particular if…
-
Whiten a matrix: Matlab & Python code
Whitening a matrix is a useful preprocessing step in data analysis. The goal is to transform matrix X into matrix Y such that Y has identity covariance matrix. This is straightforward enough, but in case you are too lazy to write such a function here’s how you can do it in Matlab: You can read…
-
Obscure Matlab function #1: bsxfun
Here’s a first in what might become a regular feature on xcorr: an exposition of some of Matlab’s obscure but quite useful functions. Today’s function: bsxfun. The Matlab documentation states that bsxfun’s function is to: Apply element-by-element binary operation to two arrays with singleton expansion enabled This is not a very helpful definition. What bsxfun(@op,A,B)…
-
Loading huge matrices in Matlab with memmapfile
It sometimes happens that I need to work with huge matrices in Matlab – too large to fit into RAM (and I have 12GB of RAM on my work computer). A classic example is when doing reverse correlation with long sequences of images. There are a few ways to work with such a large dataset.…