Managing Your Search Path in Matlab – Part I

Management of your search path in Matlab is an important skill that every Matlab programmer should have.  Your search path is the ordered set of directories that Matlab uses to find a function that you call.  Being aware of your search path is a good habit, especially if you are working with multiple versions of the same code.  In this post and the following post, I will describe how to use Matlab to modify your search path. Continue reading

Clustering Part 1 – Binary Classification

Binary classification is the act of discriminating an item into one of two groups based on specified measures or variables. While previously we have discussed methods for determining values of logic gates using neural networks (Part 1 and Part 2), we will begin a series on clustering algorithms that can be performed in Matlab, including the use of k-means clustering and Gaussian Mixture Models. Prior to doing so, we will discuss how classification is evaluated, primarily through the discussion of sensitivity, specificity and the way to calculate these values through Matlab.

Continue reading

How to Do a 2-D Fourier Transform in Matlab

In today’s post, I will show you how to perform a two-dimensional Fast Fourier Transform in Matlab.  The 2D Fourier Transform is an indispensable tool in many fields, including image processing, radar, optics and machine vision.  In image processing, the 2D Fourier Transform allows one to see the frequency spectrum of the data in both dimensions and lets one visualize filtering operations more easily.  In radar, the 2D Fourier Transform is used as a fast way to create a map from a series of coherent radar pulses.  Additionally, the far-field pattern of a 2D antenna can be calculated using a 2D Fourier Transform.  In Fourier Optics, the 2D Fourier Transform is used to calculate the propagation of electromagnetic waves and through space and optical elements. Continue reading

Neural Networks – A Multilayer Perceptron in Matlab

Previously, Matlab Geeks discussed a simple perceptron, which involves feed-forward learning based on two layers: inputs and outputs. Today we’re going to add a little more complexity by including a third layer, or a hidden layer into the network. A reason for doing so is based on the concept of linear separability. While logic gates like “OR”, “AND” or “NAND” can have 0’s and 1’s separated by a single line (or hyperplane in multiple dimensions), this linear separation is not possible for “XOR” (exclusive OR).

Linear separability for OR and XOR logic gates

Continue reading

Modeling with ODEs in Matlab – Part 2

Hello again! Today I’m back with Lesson 2 of our ongoing five part series on ODE modeling. Previously, Lesson 1 introduced the use of ODEs as a method of modeling population dynamics and discussed a simple method of evaluating the equations. Today, we will look at Matlab’s implementation of the Runge-Kutta method for solving ODEs. Lesson 3 will explore techniques for designing more realistic models. Lesson 4 will discuss methods for matching these abstract models to empirical data. Finally, we will play around with some fun ‘chaotic’ systems in Lesson 5.
Continue reading

Vectorization in Matlab Not Always Necessary

What separates Matlab from many other programming languages is the ability to vectorize code.  Vectorization allows a programmer to write code that is more intuitive, more concise, and often faster than using standard for, while and if statements.  If you have to do a large data processing task or need to create real-time application that does a large number of mathematical operations, vectorization is often a good option.  However, vectorization is not always the faster alternative for time-sensitive tasks.   I created tests for six tasks and compared the amount of time needed to run the vectorized and non-vectorized code.  The results were mixed, showing a decrease in running time for vectorized code on some tasks and a increase in running time on other tasks.  Tests involving mathematical operations ran faster using vectorized code, while tests involving conditional operators and vector creation ran faster for non-vectorized code.

[table id=13 /] Continue reading

Modeling with ODEs in Matlab – Part 1

Hi everyone!  Today I am posting the first of a planned five part series on using Matlab to simulate systems of ordinary differential equations (ODEs).  This lesson will explore the meaning of a differential equation and look at a few possible ways to solve it.  Lesson Two will look at better ways to evaluate ODEs. Lesson Three will discuss designing and simulating models using systems of ODEs.  Lesson Four will explore ways to fit these models to empirical data.  Finally, we will examine some fun nonlinear ODEs and discuss ways to deal with their complexity in Lesson Five.
Continue reading

Neural Networks – A perceptron in Matlab

Neural networks can be used to determine relationships and patterns between inputs and outputs. A simple single layer feed forward neural network which has a to ability to learn and differentiate data sets is known as a perceptron.

Single layer feed forward perceptron

By iteratively “learning” the weights, it is possible for the perceptron to find a solution to linearly separable data (data that can be separated by a hyperplane). In this example, we will run a simple perceptron to determine the solution to a 2-input OR.
Continue reading