Array subsetting with True-False matrices and FIND in Matlab
Today's lecture will focus on some tools that you can use to explore your dataset a little more closely.
Along the way, we will teach you two important concepts that we use heavily in data analysis.
First we will go over some syntax that will help you construct some special arrays very quickly.
Then we will introduce the find function in Matlab that helps you search for values in your data.
For the remaining class time, you will be able to use these tools to create several different kinds of plots in Matlab.
Reminder of the Matlab help documentation
Array Construction
Several different kinds of plots require use to temporarily make our own "data".
For example, you may have found this out when creating your histogram.
The second argument in the hist function is an array of numbers that defines your center of each bin.
For a histogram of number of earthquakes per year, this function requires us to make an array that contained each year from 1973 through 2009.
You can either create this vector of number by:
In the above example, tf is a new matrix filled with 1's and 0's.
There is a 1 where the conditional of A > 5 was true, and 0 where it was false.
How about
Note in the latter case, the use of the == to mean the test if they are equal and how that varies from the single = which is the assignment of the result to the tf variable.
Let's go back to:
>> A
A =
1 5 0
0 9 5
>> tf = A > 5
tf =
0 0 0
0 1 0
Look at the MATLAB documentation for find.
Basically it returns the array locations where values are == 1.
In combination with the conditional or boolean statement like the tf examples above, it is very powerful for processing data.
figure is a command used to initialize a new figure window.
If you just type it in, it will display and empty figure window.
Typing figure(1) makes the window "Figure 1" the current figure window.
Yes, you can have multiple figure windows open at the same time.
Typing figure(2) would make the window "Figure 2" current, and so on.
So any plotting commands used subsequently will be displayed in the current figure window.
clf will clear the current figure window of all plots that are in it.
hold on is a VERY useful function to learn when making plots.
As in the previous example, we wanted to first plot all the earthquakes.
Then, we wanted to "overlay" circles around the 2008 events.
If we were to type:
the second plot command would "blow away" the first earthquakes that we plotted.
So hold on, tells Matlab to "hold on! We've got some more stuff to plot here!"
To then release the figure, so that the next plot command will replace the figure, we can type hold off.
Video example:
In-Class Work
We can now work on building up your Matlab plotting toolbox by exploring the Yellowstone data a little more.
Choose at least one other plot type and explore some of the features within the dataset.
Here is a list of possible selections to help guide your creative thinking:
Earthquake locations: color coded by year
HINT: you may want to explore isolating individual years of peak activity