These books from the publisher Springer describe the use of Matlab in Earth Science related settings, and are available as "free" PDFs from our campus library. You can download them from below to your own computers.

- Matlab Recipes for Earth Sciences.
**CH2 provides and introduction to using Matlab**. - Signal and Noise in Geosciences: Matlab Recipes for Data Acquisition in Earth Sciences.
**CH2 provides and introduction to using Matlab**. - Matlab and Design Recipes for Earth Sciences: How to Collect, Process, and Present Geoscientific Information

You can install Matlab on you personal computer → you need a Matlab account (using your Cal Poly email), and a good internet connection!

When Matlab is open, we can exmaine the interface: Command Window, Command History, Directory Browser, Workspace (variable windo). The toolbar strips also have a lot of functionality we will examine as needed.

- Executing single and multiple commands in the Command Window
- Matlab = Matrix Laboratory. Generating vector/matrix data. Executing functions over data
- Basic Plotting
- Saving sets of Matlab commands: "scripts", or "m-files"
- Organizing scripts with comments and cells
- Organizing your directories: Matlab's default directory, Matlab's search path, the "startup.m" file

The following principles are common amongst essentially all programming languages whether they are designed primarily for computational programming or not. In our case you might consider languages such as R and RStudio, (Scientific) Python, and Julia to be "peer languages" to Matlab.

Remember, Matlab also has a near syntactic clone called Octave (but with less functionality), as well as SciLab, which has a very similar language syntax but does not specifically try to clone Matlab. Both of these are free to download and use.

- Functions → saving code files for reuse by other code files to accomplish frequently needed tasks (e.g. calculating the maximum value of a matrix or array of any dimension).
- Matlab Documentation
- To illustrate functions download rcweir.m and a driver Live Editor script rcweirLiveScript.mlx. Do this by "right-clicking" and using Save Link As to your Matlab directory.
- Branching Logic or If-Then-Else structures → this allows your code to perform one thing or another depending on the results of some test. For example, if a vector has a negative value in it this might be indicative of an error in the data and so you want to then perform a different set of program commands than if there was no error.
- Loop Structures → Suppose you need to "loop" through a data vector, doing something to each entry, such as converting Fahrenheit to Celsius.
- Matlab Documentation
- Here is the script simpleCollatz.m which illustrates the use of a
*while*loop.

Matlab's *Live Editor* or *Computational Notebook* allows you to combine code, code output (incl. figures), text formatting, mathematical notation, tables, etc.

This file can also be shared for others to interactively use, and exported to a variety of formats incluing html (make a quick webpage), PDF, etc.

- Live Editor overview - see included links
- What is Live Editor? (Video) - see included links
- Using the Live Editor - see -included links
- Matlab Live Editor Formatting Tips.

Back to the GEOL 3301 Homepage