Don't like this style? Click here to change it! blue.css

Class 18: Intro to MATLAB

MATLAB = MATrix LABoratory

How do I access MATLAB? Two options (plus one):

Why are we learning this?

I don't like learning this way, what can I do? Here are other resources for learning MATLAB:

OK, let's do this.

Hello World

Hello World Task 1: Head over to http://octave-online.net/ and in the Command Prompt run the command: disp('Hello world!')

Saved Script Task 2: If you register using gmail (your udel account) then you can save a script. In MATLAB scripts are saved as *.m files. So save a file names hello.m which displays your name.

In my opinion, the number one indicator of your success is the extent to which you demonstrate self-determinism. As young coders this means that you must always begin a new language by learning how to access documentation.

We get help with MATLAB (and Octet) by using help * and doc *

Get Help Task 3: Type help disp. Then type doc disp. Based on your findings what is another function which displays output to the screen?

The Internet is our friend Task 4: Use the internet to figure out how to "roll a die" in MATLAB (that is generate a uniform random integer from 1 to 6 inclusive).

Tab completion also works!

Comparing with Python

Here is a comparison of Python and MATLAB (matlab-python-cheatsheet.pdf borrowed from Andy Roosen, thanks):

Attempt Task 5: Use MATLAB (Octave) to tell me the terms in the sequence that starts at 3 ends at 30 and takes steps of size 7.

Translator Challenge Task 6: Write a program that rolls a die 100 times and displays the number of times each number was rolled. Hint: work with the tools you have and blah += 1 works the same way it did in Python.

Everything is a matrix

If you've never dealt with matrices before you can think of them as "lists containing fixed-length lists". The term vector is used for a single row or a single column (called a row vector or column vector, respectively).

In MATLAB everything is a matrix, so to use it well you have to think that way.

One of the most important things to understand is the indexing:

Play Task 7: Try the following operation: a = 1:10. Now run b = a + 10. Now c = a + b. Now execute a * c' and a' * c. What do you think happened?

Predict Task 8: Now predict what will happen when you perform a*3.

Mind Blowing Task 9: Now execute surf(a' * c).

Super Mind Blown Task 10: Now execute surf(sin(a)' * cos(c))!

Play Task 11: Now try plot(1:0.1:1.9, a).

Infer Task 11: Try to make a nice sine wave plot.

Let's chat about all that happened there.

Daily Challenge

Figure out how to plot the bell curve (a normal distribution), and make a nice plot for me.