Archive | Matlab RSS feed for this section
Matlab Tips in Signal Processing
Moving average filter To compute an N-sample moving average of x with zero padding: For large N, it is faster to use Locating zero-crossings and extrema To obtain the indices where signal x crosses zero: Linear interpolation can be used for subsample estimates of zero-crossing locations: Since local maximum and minimum points of a signal [...]
How to Install Python as a Replacement to Matlab
Python has matured to the point where it is a very powerful computational environment with flexibility that is unmatched by any commercial product. But this flexibility comes at the cost of a very fragmented install procedure. The default installation of python is feature poor and the needed features for computations are spread out over many [...]
How Long are Movies?
Background: Going to the movies requires the larger part of an evening and it is not uncommon to rent movies spanning two DVDs. Fueled by this observation I explore data published by the Internet Movie Database to test the hypothesis that movies are getting longer. Leading to the conclusion that movies have had a constant [...]
Matlab Quick Reference: Plot
Matlab figure title with two lines 12345678910clc plot(1:10) title({‘Comparison of Results’;'using Mean Squared Error (MSE)’}) set(gca, ‘Units’, ‘Normalized’) P=get(gca,’Position’); % Shrink the bottom margin by half its height and % enlarge the top margin by the same amount % (since the axis is the same height before & after) set(gca, ‘Position’, [P(1) P(2)/2 P(3) [...]
Matlab Quick Reference: Input/Ouput
I/O Extract date from file 12s = dir(‘junk.m’); s.date Open a formatted text file 1fid = fopen(‘file.dat’,'w’) w: write r: read a: append returns -1 if error If the file is a text file and you want to write to it, consider using ‘t’ as an attribute if you want Windows line break [...]
Matlab Quick Reference: Functions
Functions Syntax 12345function y = average(x) % AVERAGE Mean of vector elements. % only first comment line is printed when you type “lookfor average” % the other lines print when you type “help average” y = sum(x)/length(x); % Actual computation 1function [Xout,Yout] = myFunc(x) Number Of Arguments nargin: number of input arguments nargout: number of [...]
Matlab Quick Reference: General
My Matlab quick reference: General notes
Faster Matlab Calculation: Use Preallocation
Preallocation I am a believer in preallocation. For a particular application, I read in about 13GB of data from a file into a 4-D matrix (this was running on a machine with 32GB of memory). Before preallocation, I let the process run for about 10 hours, and it still hadn’t finished. With preallocation the process [...]

