abs(data)
If data comprises real-valued numbers, abs returns their absolute values. If data comprises complex numbers, abs returns their magnitude (the length of a line in complex space starting from the [0,0] origin and ending at a point defined by the real and imaginary coordinates). In time-frequency analyses, abs is most often used to obtain amplitude information from Fourier coefficients or the result of complex Morlet wavelet convolution.

angle(data)
Returns the angle of a complex number, which is to say, the angle in radians formed between the origin of a complex plane and a vector drawn from the origin to a point described by a complex number, relative to the positive real axis.

bar(x,y)
Produces a bar plot of y using x-axis coordinates in x. If only y is inputted, x is assumed to be integer values from 1 to length(y).

bsxfun(@function,a,b)
Applies @function to vectors or matrices a and b. a and b can be different sizes, as long as the size of one dimension matches. Often, bsxfun can be used instead of repmat. @function can be one of several built-in functions such as @times, @rdivide, @add, or can be a user-defined function.

cat(dim,a,b)
Concatenate matrices a and b along dimension dim. In some cases, it may be easier to concatenate via square brackets, as in [a b] or [a; b].

ceil(data)
Round up to the nearest integer. For example, ceil(1.0001) is 2.

colorbar
Adds a colorbar to the current axis. This facilitates understanding the mapping between color in an image, and numerical values in the data. If a colorbar is already present, typing colorbar again will remove the colorbar.

contourf(x,y,data,N,'linecolor','none')
Produces a smooth image of 2D matrix data with x-axis and y-axis coordinates x and y. N refers to the number of contour lines; more lines produce a smoother-looking plot, but may take longer to render. For many images, between 20 and 50 lines is sufficient. 'linecolor','none' produces an image without explicit contour lines, and is more easily interpretable for N>10. Without this option, contourf will draw black lines for each contour.

conv(data,kernel)
Returns the result of convolution between data and kernel. The result will be of length D+K-1, where D is the length of data and K is the length of kernel. In Matlab (not Octave), an optional third input can be provided ('same') that automatically trims the result of convolution such that it is the same length as data.

cos(data)
Returns the cosine transform of data.

cumsum(data)
Returns the cumulative sum, meaning that at each point in data, the return value is the sum from the first point in data to the current point. For example, cumsum([1 3 1 5]) is [1 4 5 10].

detrend(data)
Removes a linear trend from data. This is also used to remove DC offsets. This can be useful during processing/cleaning, because some forms of noise produce slow linear drifts. Detrending can also remove mean non-stationarities if those non-stationarities are linear or approximately linear.

diff(data,N,dim)
Computes the N-order derivative (difference over successive elements) along dimension dim. Note that the result will contain one element fewer compared to data. It is thus often useful to add an extra data point to the derivative; this may simplify subsequent programming and analyses. For example: xd=diff(x); xd(end+1)=xd(end);

disp(statement)
Prints statement to the Matlab command prompt. It is often used to update progress during long analyses. For example, at the end of a loop over channels (looping index chani) there could be disp([ 'Finished analyzing channel' num2str(chani) '.' ]). This would print in the Matlab command prompt as "Finished analyzing channel 34."

double(data)
Converts the single-precision or Boolean (true/false) data to floating-point precision. Storing data in single precision is often useful to reduce variable and file sizes. Converting to floating-point precision is necessary for some plotting and filtering functions. Note that converting numerical data to single precision can result in information loss, depending on the scale of the data.

dpss(pnt,N)
Returns 2N pnt-length discrete prolate Slepian sequences. These are used as tapers during a multitaper analysis. This function is part of the Signal processing toolbox of Matlab. As of summer 2014, it is not available in Octave.

dsearchn(data,values)
Finds the indices in data closest to values. dsearchn expects column-format data. Thus, if dsearchn produces an error, try first to transpose either or both of data and values.

exp(k)
Natural exponent to the power of k (ek).

fft(data,N,dim)
Returns the fast Fourier transform of data, using N points. data will be zero-padded if N is larger than size(data,dim), and data will be truncated if shorter. The default N is size(data,dim). If data is a matrix, the FFT will be computed over dimension dim.

filtfilt(kernel,1,data)
Apply a zero-phase-shift time-domain filter specified by kernel on data. The second input is a weighting vector, and is often set to 1 (thus, no weighting). kernel can be created by Matlab functions such as firls or fir1, which are in the Signal Processing toolbox in Matlab or the Signal package in Octave.

firls(order,frex,shape)
Computes and returns a time-domain filter kernel of length order for frequencies specified by frex and corresponding to the frequency-domain shape shape. The order must be larger than the lowest frequency, and is typically set to between 3 and 10 times as long as the lowest frequency (thus, if the lower frequency filter bound is 10 Hz, order should be at least 300 ms). Narrow-frequency-band activity may be better resolved with relatively higher orders. frex is a vector of frequencies between 0 (DC) and 1, which correspond to fractions of the Nyquist frequency. For example, if the sampling rate is 500 Hz, 25 Hz corresponds to 0.1. shape is the desired ("ideal") frequency response shape. In most cases, this is specified as a plateau with softened edges. The shape and frex vectors must have the same number of elements. A simple plateau-shaped filter should have six points: 0, start of lower transition zone, lower frequency bound, upper frequency bound, end of upper transition zone, and Nyquist. This function is in the Signal Processing toolbox in Matlab or the Signal package in Octave.

floor(data)
Rounds down data to the nearest integer. For example, floor(1.9999) is 1, and floor(-1.9999) is -2. To round to the integer closest to zero (thus, floor if positive and ceil if negative), use fix(data).

for i=1:5, ..., end
Loop (in this example) 5 times and run the commands listed before end. The variable i is automatically incremented immediately before end. Loops can be escaped with break, and individual iterations can be skipped with continue. For example, to skip iteration 2:

for i=1:5
if i==2, continue; end
disp(num2str(i));
end
get(gca,'property')
Returns the value of the requested property of the current (most recently used, or mouse-clicked) axis. gca can be replaced with an axis or figure handle if one is created. Common uses of get are to find the x-axis or y-axis limits, for example get(gca,'xlim'). For a list of properties, type get(gca) or get(gcf).

hilbert(data)
Returns the Hilbert transform of data. This function is contained in the Matlab Signal processing toolbox, or the Octave Signal package. However, it can be created using the explanation in Chapter 7.1. This function accepts matrices, but will always compute the Hilbert transform along columns. If data are organized as channels X time, it will be necessary to transpose data first (and it might be useful to transpose the results after the Hilbert transform). When in doubt, input only a single vector into the function to match the output against the output of matrix input.

[y,x]=hist(d,n)
Generates a histogram of data d using n bins. If no outputs are requested, a plot is generated. The histogram can be recreated with the outputs as plot(x,y).

hold on/hold off/hold all
Freezes the active plot so that new plot commands draw on top of, rather than replacing, the current graph. The active plot can be called from the command (see subplot and figure) or clicked on with a mouse. hold all additionally preserves the order of setting line colors.

if ... elseif ... else ... end
A conditional control statement that runs a section of code only if what appears after if is true. if and end are required; elseif and else are optional. Below is an example.

i=4;
if i==2
disp('2')
elseif i==3
disp('3')
else
disp('not 2 or 3')
end

ifft(data,N,dim)
Returns the N-point fast inverse Fourier transform of data along dimension dim.

imag(data)
Returns the imaginary part of a complex number (or vector or matrix). If the input is real-valued only, imag returns 0.

interp1(x,y,t,'spline')
Performs linear interpolation of values in y at time points in x, over the points t. t must be in the same range as x. For example, the following code will perform a spline interpolation of three points over 20 points. y = interp1(1:3,[5 12 -4],linspace(1,3,20),'spline');

legend({'a';'b';'c'})
Places a legend in the current plot. The order of texts in the cell array must match the order in which the data were plotted.

length(data)
Returns the number of elements in the longest dimension of matrix data. If there is uncertainty as to which dimension length is returning, it is better to use the function size.

linspace(low,high,N)
Returns N linearly spaced numbers between low and high.

log(data)
Returns the natural logarithm of data. Remember that the logarithm of zero is not defined, and the logarithm of a negative number is complex. If you might have zeros in the data, use log(data+eps) to add a tiny number to data. If you have negative values, you can use log(data-min(data)+eps).

logspace(low,high,N)
Returns  N logarithmically spaced numbers between low and high. Note that low and high are interpreted as power-of-10. Thus, to obtain six logarithmically spaced numbers between 4 and 20, type logspace(log10(4),log10(20),6).

[val,idx]=max(data)
Returns both the value and the index (location in the matrix) of the largest number in data.

mean(data,dim)
Computes the arithmetic mean of matrix data along dimension dim.

[val,idx]=min(data)
Returns both the value and the index of the smallest number (that is, the left-most on the number line; thus, -10 is smaller than 0) in data. min can be used in combination with abs to find the point in a vector that is closest to a desired value. For example, [val,idx]=min(abs([1 2 5 6]-4.6)); will return idx of 3, indicating that the 3rd element in the [] array is closest to 4.6.

mod(data,n)
Returns the modulus of data by n, in other words, the integer remainder when dividing data by n.

nextpow2(N)
Returns the number m such that 2m is the next power-of-2 greater than N. For example, nextpow2(3) is 2, meaning that 2^2 is the first power-of-2 number that is greater than 3. It is often used when determining how much to zero-pad a time series to maximize the efficiency of a fast Fourier transform.

num2str(data)
Converts the number in data to a text string. This is often used when generating plot labels.

numel(data)
Returns the total number of elements in data, regardless of the number of dimensions. For example, if data were a 2x5x8x6 matrix, numel(data) would be 480.

plot(x,d,'r-','linewidth',3)
Plots data d as a function of x-axis values x. This function can take one- or two-dimensional data. 'r-' refers to a red dashed line. 'linewidth',3 refers to the thickness of the lines. Type help plot for additional plotting options.

plot3(x,y,z)
Similar to plot, except for 3D data. Vectors x, y, and z must have equal length. It is often useful to visualize 3D plots by moving them around in space with the mouse. In Octave, this function is on by default; in Matlab, it can be activated with rotate3d (or by clicking on the rotate button on the top of the figure).

p=polyfit(x,y,o)
Computes a polynomial fit of variable x to variable y, using an order of o. Output p contains a vector of o+1 coefficients, where the final coefficient is the intercept (the value on the y-axis when the predicted function is at 0 on the x-axis). The resulting prediction of y based on x and p can be evaluated using yy=polyval(p,x);.

prod(data)
Returns the product (multiplication) of all elements in data. For example, if data were a matrix [2 4 1 7], the result of prod would be 56.

rand(dims)
Returns randomly generated numbers with a uniform distribution between 0 and 1. The inputs to rand are the size of the matrix (dims). Note that giving one input N defaults to an NxN matrix; a 1xN vector is created with rand(1,N). To create uniformly distributed random numbers between arbitrary numbers a and b, type a+(b-a)*rand(dims).

randn(size)
Same as rand but produces normally distributed numbers (mean of zero, variance of one). To create random numbers with mean a and standard deviation b, type a+b*randn(dims).

real(complexnumber)
Extracts the real part of a complex number.

reshape(data,new_dims)
Changes the shape of data to be new_dims. For example, if data is a 1x10 vector and new_dims is [2 5], the output of this function will be a 2x5 matrix (be careful here: this is different from reshaping to [5 2]). The number of elements in data must be the same as the size of new_dims. That is, numel(data) must equal prod(new_dims).

repmat(data,a,b)
Repeats matrix data a by b times. For example, if data were [1 2], repmat(data,1,2) would be [1 2 1 2] and repmat(data,2,1) would be [1 2; 1 2]. Higher dimensional replications are also possible. This function is most often used when multiplying two matrices of different sizes, for example, when multiplying a 1x4 matrix by each row of a 200x4 matrix.

rotate3d
Allows click-and-drag rotation of plots or images. This function is necessary only in Matlab, not in Octave.

round(data)
Rounds to the nearest integer. To round to the nearest decimal, use round(data*N)/N, where N is the nth decimal to round to in power-of-ten (10, 100, 1000, etc.).

set(gca,'property',value)
Changes aspects of a axis. gca indicates the current axis (the one most recently used, or most recently mouse-clicked), or can be replaced with a handle (e.g., h=plot(rand(3)); set(h,...)). 'property',value refer to changeable properties and their new values, for example, set(gca,'xlim',[0 100]) changes the x-axis limit.

sin(x)
Returns the sine function of x. It is typically used to generate a sine wave as a*sin(2*pi*f*t+p), where a is the amplitude, f is the frequency, t is time (in seconds if f is specified in Hz), and p is the phase.

size(data[,dim])
Returns the sizes of each dimension (that is, the number of elements) of matrix data. If you want to know the total number of elements in a matrix, use either prod(size(data)) or numel(data). If the optional second input dim is provided, only the number of elements along dimension dim will be returned. For example, if data is a 3x4x2x10 matrix, size(data,3) will return 2.

[vals,idx]=sort(data)
Sorts data according to ascending values. idx contains the new indices. Thus, data(idx) is the same thing as vals.

squeeze(data)
Removes singeton dimensions of data. For example, if data were a 4x1x8x1x3 matrix, squeeze(data) would be a 4x8x3 matrix. This is often necessary when plotting or imaging parts of high-dimensional matrices.

std(data,[],dim)
Returns the standard deviation of data along dimension dim. The second input can be set to 1 for normalization by N instead of N-1. In most cases, samples (rather than the entire population of data) are provided, and thus N-1 is the appropriate normalization.

subplot(c,r,i)
Divides the figure into c columns and r rows, and sets subplot i to be the current.

sum(data,dim)
Computes the sum (addition of all elements) over dimension dim.

switch/case/otherwise/end
A switch statement is a conditional, similar to the if-then statement. The value of the variable after switch is compared for each case. If none of the cases match, the optional otherwise will be evaluated. See below for an example.

val = 2;
switch val
case 1
disp('val is one');
case 2
disp('val is two');
case 3
disp('val is three');
otherwise
disp('val is out of range.');
end

title('text')
Gives a title to the current plot.

unwrap(phases)
"Unwraps" phase angles in phases (in radians). This means that 2pi is added to the phase angles whenever they would otherwise return to -2pi. This is used when computing the derivative of phase, which is part of computing instantaneous frequencies.

view([az el]])
Sets the orientation of a 3D plot (generated by, e.g., plot3 or surf) according to the azimuth (az) and elevation (el). Values range from -90 to +90. By clicking-and-dragging the plot around, the current azimuth and elevation are printed in the lower left of the Matlab figure.

while ... end
Continuously runs a set of code as long as the Boolean expression after while is true. For example, the code below will continue generating random numbers until a number is bigger than 1.8.

aRandomNumber = randn;
while aRandomNumber<1.8
aRandomNumber = randn
end

xlabel('text')
Gives a label to the x-axis of the current plot.

ylabel('text')
Gives a label to the y-axis of the current plot.

zeros(dims)
Create a matrix entirely of zeros, of specified size dims. This is often used to initialize variables. Note that zeros(N) produces an NxN matrix of zeros. To produce a vector, use zeros(1,N) or zeros(N,1).

zlabel('text')
Gives a label to the z-axis of the current plot.