Published on GEOSC 444: Matlab Application for Geoscience (https://www.e-education.psu.edu/geosc444)

Home > Lessons

Lessons

Lesson 1: Getting started with Matlab

Overview

Lesson 1 introduces the most basic features of MATLAB.

  • MATLAB as a calculator
  • getting command help inside MATLAB
  • naming variables
  • operation precedence
  • punctuation, MATLAB intrinsic variables and functions
  • how some computations in MATLAB are different from those in a spreadsheet program

Learning Outcomes

By the end of this lesson, you should be able to:

  • use MATLAB to perform simple calculations and solve simple algebra and trig problems
  • identify valid variable names
  • know where to look for how-to help within MATLAB

Lesson Roadmap

Lesson Roadmap
To Read Lesson pages
To Do
  • Download/install MATLAB and/or login to psu's webapps to use MATLAB.
  • Work through example activities in the lesson 1 pages
  • Work through self-check quiz at the end of the lesson.
  • Take low-stakes quiz
To Deliver Quiz in Canvas

Questions?

If you have questions, please feel free to post them to the Questions?  forum in Canvas. I will check this forum daily. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 1: Fire it up

Syntax introduced:

+=ans;whosiskeyword

Once you've installed MATLAB and started it, or logged into it through PSU's webapps, you are presented with an interface that looks like this.

MATLAB interface screenshot
MATLAB 7 command interface

The central panel is the Command Window, where you can type what you want MATLAB to do. Go ahead and put your cursor in there right now. Type an obvious math problem such as 3 + 4 and then hit return. You should get back:

>> 3+4 ans =      7 >>

with a blinking cursor after the last >>

Good! You're on the way to being an expert already. The ans is short for "answer" and it is also a temporary variable that you could use in the very next command. Try typing ans+2 and you'll see that MATLAB will reassign the value 9 to ans.

Assigning variables

To assign a variable in MATLAB first type the name of the variable and then use a single equals sign to set that variable equal to whatever value you want to give it. For example, to make a variable called "a" that is equal to 3, type a=3 into the command window. MATLAB tells you:

>>a=3
a =
    3
>>

If you don't want MATLAB to repeat everything back to you, type a semicolon at the end of your command, as in a=3;

You can also tell MATLAB to assign the results of a calculation to a variable. For example, type b=a+4;

MATLAB has now behind the scenes assigned the value 7 to b. If you look over at the Workspace panel on the right, you'll see a listing of variables there. Another way to find out what variables are currently in use the the command whos. If you ever want to know the value of a variable without looking at the Workspace panel you can just type the name of the variable and hit return.

Rules about naming variables

Variables can't start with a number and cannot have spaces in them, but they can be a whole word or phrase as long as you jam the words together. Most people use underscores or camel case for readability. Variables are also case sensitive. Some people like to use conventions such as capitalizing matrices and using lowercase for vectors and scalars. MATLAB doesn't care how you go about it, but sometimes adhering to a consistent naming scheme makes your programs more human-readable, thus making you a more popular collaborator.

Variable name checklist
Variable OK? notes
x yes
X yes capital X is a different variable than lowercase x
1x no don't start a variable name with a number
x1 yes variables can have numbers in their names as long as they aren't first
eliza is cool no variable names can't have spaces, even if the sentence is a true statement
eliza_is_cool yes totally
elizaIsCool yes camel case is fine
eliza.is.cool no don't use punctuation other than the underscore because most of them have special values
for no don't use any keywords that are on the reserved list. the command iskeyword tells you what's on the list
fourScoreAndSevenYearsAgo yes but there isn't room for the whole Gettysburg Address because variable names can have a maximum of 63 characters

Check yourself!

Lesson 1: Help, arithmetic, precedence

Syntax introduced:

helplookfor-*/\^( )

Time to introduce my two favorite MATLAB commands: help and lookfor. If you type help commandName MATLAB will print to the screen the manual page for that command together with examples. This is a great resource, but it only works perfectly well if you already know the name of the command and you are merely wanting to double check its usage. Sometimes you can't remember the exact name of the command but you have a guess, or at least you have an idea that there is a command that does something similar to what you want. In this case lookfor is your new best friend because it will find and list all the commands that have part of the word you typed. Try it out for yourself!

Arithmetic

MATLAB works like a calculator and supports the obvious math operations commonly found on your keyboard such as + (addition) -(subtraction) *(multiplication) / \ (left and right division). Use ^ to raise a number to a power. For example, if you type a=3;b=4;c=b^a MATLAB reports back to you that the value of c is 64. That's because you set a equal to 3 and you set b equal to 4 and then you set c equal to b raised to the power of a. 4 cubed is 64, so we're good.

Other algebraic expressions work as expected. For example, raising a number to a negative power is equivalent to writing 1 over that number raised to the same power. For example, following on our previous work in which a = 3 and b = 4:

>>a^(-b)
ans =
    0.0123
>> 1/(a^b)
ans =
    0.0123

Operation precedence

Precedence refers to the order in which mathematical operations are executed. If you can recall back to any algebra classes you took before college, you probably remember the rules of precedence. MATLAB follows the standard rules, which are

  • expressions are evaluated left to right
  • exponentiation is first
  • multiplication and division are next
  • addition and subtraction are last

If you want to change the order, then use parentheses. Expressions are evaluated from the innermost set of parentheses outwards, with the rules listed above applying within each nested set of parentheses.

Check yourself!

Lesson 1: Two little surprises that can trip you up

Syntax introduced:

log log10 sin sind pi

One of the rare counterintuitive (to me anyway) commands is log. When I see "log" written I always assume base 10, whereas "ln" means natural log (base e). But that's not how MATLAB expresses it. In MATLAB,log means natural log. If you want base 10, use log10.

Surprise #2 is that the default for trig functions (sine, cosine, tangent, etc.) is radians. To convert to degrees instead, multiply your angle by pi/180 or else use sind. "pi" is a "special variable" in MATLAB. By default you can just type the word to use it. The "d" in sind to make MATLAB use degrees also works for other trig functions, like, for example, cosd and tand.

Here's a tip: If you are ever working with a programming language, spreadsheet program, or calculator and you aren't sure whether you are working in degrees or radians, just try calculating the trig function of an angle that has an obvious well-known answer, such as the sine of 90 degrees:

>> sin(90)
ans =
   0.8940
>> sin(90*pi/180)
ans =
   1
>> sind(90)
ans =
   1
The first time we tried it, we didn't get 1 as the answer so this means we know we must not be working in degrees. Therefore, either multiply 90 by pi/180 and take the sine of that quantity, or else use sind. We get back the answer 1, so now we know what we are doing.

Check yourself!

Lesson 1: A big difference between MATLAB and a spreadsheet program

Reassigning a variable to a new value does not automatically re-perform any past calculations involving that variable. For example, see the following set of commands:

>> a=3;b=4;
>> c=a+b
c =
     7
>> a=5;
>> c
c =
     7

In this series of operations, I first set a equal to 3 and b equal to 4. I set c equal to the sum of a and b. MATLAB tells me c is 7. So far, so good. Then I set a equal to 5. In a spreadsheet program, c would be recalculated to take into account the new value of a but MATLAB doesn't do that, which I can verify by typing c to find out its value. MATLAB tells me c is still 7.

Check yourself!

How about this one?

Lesson 1: Road check

Self Check Quiz!

Take the time to work through these problems to check your grasp of the concepts introduced so far. Tip! This is an ungraded quiz for self-checking purposes. You should start MATLAB and try out for yourself anything that you don't know the answer to.

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 1 tasks!

You have reached the end of Lesson 1! Double-check the to-do list on the Lesson 1 Overview page [1] to make sure you have completed all of the activities listed there before you begin Lesson 2.

Lesson 2: Vectors and Matrices

Overview

MATLAB is essentially vector-based, so much data that will be manipulated is commonly structured in the form of arrays of values (vectors and matrices). If you don't commonly use other programming languages, then think of arrays as the grid of values in a spreadsheet program. Mathematical operations are designed to be carried out on arrays. In this lesson we'll go through a variety of methods to create and interact with arrays.

Learning Outcomes

By the end of this lesson, you should be able to:

  • Use a variety of methods to construct arrays
  • Query the attributes of an array
  • Perform simple mathematical calculations with arrays
  • Make a simple plot on two-dimensional axes
Lesson Roadmap
To Read Lesson 2 (this web site) here
To Do
  • Lesson 2 Quiz
  • Problem Set 1
  • Canvas
  • Canvas

Questions?

If you have questions, please feel free to post them to the Questions? Discussion forum in Canvas. I will check that forum daily. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 2: make a 1D vector

Syntax introduced:

[ ] ' ( ) find linspace zeros ones eye sqrt length size reshape diag plot fplot line hold on/off axis

Make a 1D vector and query its attributes

You can create a row vector by naming each of its elements explicitly. Put them inside square brackets with commas or spaces separating elements. For example, I'm going to create a row vector and name it myVector. It's going to have 5 numbers in it.

>> myVector = [1, 75, 0.3, 1000, 2^4]

myVector =

   1.0e+03 * 
    0.0010    0.0750    0.0003    1.0000    0.0160

Okay, that's fine. Let's say I already forgot what the fourth number in myVector is. Find out by asking MATLAB. Use parentheses to specify that you want to know the value of the 4th entry:

>> myVector(4)

ans =

        1000

MATLAB will give you an error message if you try to ask it for a value that doesn't exist:

>> myVector(6)
	Index exceeds matrix dimensions.
In the example above, myVector only has 5 numbers in it, so asking for the value of the sixth number doesn't make sense. The command size is useful for reminding yourself about the dimensions of a vector or matrix. When you ask MATLAB for the size of a vector or matrix it returns a vector with two entries: the number of rows and the number of columns.
>> size(myVector)

ans =

     1     5

Logical operators

The command find is good if you want to search for specific entries:

>> find(myVector==1000)

ans =

     4
>> find(myVector>1)

ans =

     2     4     5

In the above examples using find, MATLAB returns the indices (positions) of the values of the vector that match what you were looking for, not the values themselves. When I wrote find(myVector==1000) I was asking MATLAB which number in myVector is equal to 1000. MATLAB answered that it was the 4th entry. When I wrote find(myVector>1) I was asking MATLAB which numbers in myVector have values greater than 1. MATLAB answered that the 2nd, 4th, and 5th entries are greater than 1.

screenshot of matlab command window with commands discussed on this lesson page
Screenshot of commands demonstrated on this lesson page

The difference between = and ==

One = is an assignment. It is an action. It means I am setting something equal to something else. For example: x = 3 means I am declaring that there is a variable x and its value is 3. y = [1 2 3 4 5] means I am declaring a variable y and it is a 1x5 vector whose values are 1, 2, 3, 4, and 5. If I write z=y then I've made a copy of y and called it z.

Two == is a logical test, not an assignment. It is essentially asking whether something equals something else. When I wrote find(myVector==1000) I was asking MATLAB to tell me the position in myVector whose value equals 1000.

Other common logical operators are ~ (not) > greater than < less than. Logical operators can be combined as in find(myVector>=1) which would find all the positions in myVector whose values are greater than or equal to 1.

Lesson 2: piecewise arithmetic

Syntax introduced:

mean median mode sum :

Arithmetic with vectors

Any arithmetic you perform on a vector with a scalar is by default performed piecewise on each vector element. For the following examples, I'm going to create a vector x and use it to demonstrate what I mean. You should open up MATLAB and follow along to verify my examples for yourself. First let's create x and then multiply it by 2.

>> x=[1 3 5 9 15];
>> x*2

ans =

     2     6    10    18    30

>> x

x =

     1     3     5     9    15

What is the most important thing to notice about this sequence of commands? The actual value of x didn't change even though we multiplied it by 2. Huh! Is that counterintuitive? Maybe. Think of it this way. You asked MATLAB what the answer would be if you multiplied x by 2 and it told you. If you actually want to set x equal to a new value you have to use = for assignment, like so:

>> x=[1 3 5 9 15];

>> x=x*2

x =

     2     6    10    18    30
Now you have overwritten the original value of x. Maybe you want to keep the old value of x. That's fine. Just assign a new variable to the product of x and 2, like so:

>> x=[1 3 5 9 15];

>> doubleX=x*2

doubleX =

     2     6    10    18    30

>> x

x =

     1     3     5     9    15

Addition, subtraction and division all work the same way as multiplication. I'm going to repeat what I said before because it will be important later: These element-by-element operations work like they do because in our examples, we have a one-dimensional vector, x,  and a scalar. Arrays and array operations (when x has more dimensions or there isn't a scalar) will be discussed later.

Standard simple statistical calculations such as mean, median, mode, and sum are all performed over the entire vector x unless you tell MATLAB to use a subset of the vector. Use the : to specify a range within a vector.

>> x=[1 3 5 9 15];

>> x(1:3)

ans =

     1     3     5

>> mean(x(3:5))

ans =

    9.6667

In the snippet above I asked MATLAB for the first three elements of x. Then I asked MATLAB to take the mean of the 3rd through 5th elements in x.

Check yourself!

Lesson 2: column vectors, vector math

Syntax introduced:

' .* mode sum :

Make a column vector

A column vector is created inside square brackets with semicolons or returns separating elements. You can turn a row vector into a column vector (or the other way around) with the transpose operator, which is a single quote mark '.

>> x=[2 4 6 8 10];
>> y=[1;3;5;7;9];
>> x

x =

     2     4     6     8    10

>> y

y =

     1
     3
     5
     7
     9

Vector arithmetic

Who cares whether a vector is a row vector or a column vector, you say? Well, if all of your vectors are of the same type and the same length then adding one to the other and subtracting one from the other of them works piece by piece:

>> x+x

ans =

     4     8    12    16    20

>> y+y

ans =

     2
     6
    10
    14
    18

But adding and subtracting when one vector is a row vector and the other one is a column vector doesn't work piece by piece:

>> M=x+y

M =

     3     5     7     9    11
     5     7     9    11    13
     7     9    11    13    15
     9    11    13    15    17
    11    13    15    17    19

What did MATLAB do here? It constructed a 5x5 matrix M in the following way. The first row of M is x(1)+y(1), x(2)+y(1), x(3)+y(1), x(4)+y(1), x(5)+y(1). The second row of M is x(1)+y(2), x(2)+y(2), x(3)+y(2), x(4)+y(2), x(5)+y(2). And so forth. The number of columns of one vector have to equal the number of rows of the other vector for this to work.

Dot products and cross products

You can also multiply and divide two vectors piece by piece, but you have to tell MATLAB you want to do it that way by using the dot product .*:

>> x.*x

ans =

     4    16    36    64   100

>> y.*y

ans =

     1
     9
    25
    49
    81

You'll get an error message if you try to multiply x by x by merely writing x*x. However, you can multiply x by y by just typing x*y since one of them is a column vector and the other is a row vector and the number of columns of x equals the number of rows in y. Try it! You get

>> x*y

ans =

   190

Why? Because you are basically asking MATLAB to take the cross product of two orthogonal vectors, so the answer is a scalar. The actual calculation is equivalent to:

>> x(1)*y(1)+x(2)*y(2)+x(3)*y(3)+x(4)*y(4)+x(5)*y(5)

ans =

   190

Check yourself!

Lesson 2: More efficient vector creation

Syntax introduced:

: linspace logspace

Doing it by hand is okay . . . once

Up until now we created vectors by entering each element of the vector by hand. This was okay at the time because all of our vectors were small. Most Earth science datasets and model runs, on the other hand, are large and have a lot of datapoints, and there's no way you want to be typing in values by hand. Commonly, you want a regularly spaced array in which you specify the increment or else you specify the number of data points you want and let MATLAB set the increment.

Create a vector with constant spacing

Way 1:  specify the spacing

To create a vector with spacing specified you can use the : operator and type beginningNumber : increment : endNumber. The default if you don’t specify an increment is to increment by 1. You can also use fractional numbers and negative numbers with this technique.

Way 2: specify the number of elements

Another way to create a vector with constant spacing is to use linspace and set the vector with linspace(beginningNumber , endNumber, numberOfElements). If you don’t specify the number of elements, the default is 100. MATLAB will figure out the spacing for you.

You can also create vectors with regular logarithmic spacing instead of linear spacing. In this case you use logspace and type logspace(beginningExponent, endExponent, numberOfElements). The default here is 100 elements as well.

Let's say I want to make a vector that goes from 10 to 20 by ones. We know several ways to do this by now. Here are a few:

>> x=10:1:20 
  x =     10    11    12    13    14    15    16    17    18    19    20
 
>> x=10:20 
  x =     10    11    12    13    14    15    16    17    18    19    20
 
>> x=linspace(10,20,11) 
  x =     10    11    12    13    14    15    16    17    18    19    20
 
>> x=(0:10)+10 
  x =     10    11    12    13    14    15    16    17    18    19    20
 
>> a=10:15; 
>> b=16:20; 
>> x=[a b] 
  x =     10    11    12    13    14    15    16    17    18    19    20

There's lots of ways to skin this cat.

Lesson 2: 2-D matrices, special matrices

Syntax introduced:

ones zeros eye repmat

2-D matrix creation

A 2-D matrix is created inside of square brackets with spaces or commas between elements in a row and semicolons or returns separating rows. Rows have to have the same number of elements. You can use multiple linspace or : inside the square brackets, too.

Special matrices

Special matrices include zeros(numberOfRows, numberOfColumns), ones(numberOfRows, numberOfColumns), and eye(number). The identity matrix eye, in which ones appear along the diagonal but all other elements equal zero, is always square so you just specify one number for the dimension.

>> zeros(2,3)
ans =
     0     0     0
     0     0     0
>> ones(5,2)
ans =
     1     1
     1     1
     1     1
     1     1
     1     1
>> eye(6)
ans =
     1     0     0     0     0     0
     0     1     0     0     0     0
     0     0     1     0     0     0
     0     0     0     1     0     0
     0     0     0     0     1     0
     0     0     0     0     0     1

Lesson 2: More complicated vector and array addressing

Syntax introduced:

diag reshape

We've already practiced using parentheses to address a certain element of a vector. You can also use that technique to address a specific spot in a matrix. For example, v(1) addresses the first element in a vector v. M(1,1) addresses the element in the top left corner of the matrix M. In the example below I make a 3x3 matrix M. Then I ask it for the element in the second row and third column. It's just like playing Battleship except both the columns and rows are designated by numbers.

>> M=[1 2 3; 4 5 6; 7 8 9];
M =
     1     2     3

     4     5     6

     7     8     9

>> M(2,3) 
ans = 
     6

Use the colon operator to address a range of elements in a vector or matrix. For example, v(:) addresses all the elements of a vector, v(a:b) addresses elements a through b in vector v. M(:,a) addresses column a, M(a,:) addresses row a, M(:,a:b) addresses columns a through b, M(a:b,:) addresses rows a through b, M(a:b,c:d) addresses the intersection of rows a through b and columns c through d.

>> M(:,2)
ans =
     2

     5

     8
>> M(3,:) 
ans = 
     7     8     9 
>> M(1:2,2:3) 
ans = 
     2     3

     5     6

Use a square bracket to address nonconsecutive elements in a vector or matrix. For example v([a,b,c:d]) addresses elements a, b, and c through d. M([a,b],[c:d,e]) addresses the intersection of rows a and b and columns c through d and e.

>> M([1,3],1:3)
ans =
     1     2     3

     7     8     9

Other games you can play

To append an element to a vector just specify a value at the desired position. If it is not the next consecutive position, MATLAB pads the elements in between with zeros. You can append existing vectors to each other if they are all row vectors or all column vectors.

>> v=1:20;
>> v(25)=7.6
v =
  Columns 1 through 9
    1.0000    2.0000    3.0000    4.0000    5.0000    6.0000    7.0000    8.0000    9.0000
  Columns 10 through 18
   10.0000   11.0000   12.0000   13.0000   14.0000   15.0000   16.0000   17.0000   18.0000
  Columns 19 through 25
   19.0000   20.0000         0         0         0         0    7.6000

To append vectors to a matrix you need to make sure the dimensions work out so that all rows have the same number of elements.

Use empty brackets to delete an element from a vector or a row/column from a matrix. Deleting is not the same as assigning zero to the value of that element. Using empty brackets to delete elements from a matrix works if you are going to delete a whole row or a whole column, but not just one element. See in the snippet below a successful deletion of the fourth element of a vector, and what happens when I try to delete just one element from a 4x3 matrix.

>> v=[1:5];
>> v(4)=[]
v =
     1     2     3     5
>> M=ones(4,3);
>> M(1,1)=[]
A null assignment can have only one non-colon index.

diag on a vector creates a matrix whose diagonal is the initial vector and whose other elements are zero. With a matrix, diag pulls out the diagonal elements and makes a vector out of them.

>> v=1:5
v =
     1     2     3     4     5
>> diag(v)
ans =
     1     0     0     0     0
     0     2     0     0     0
     0     0     3     0     0
     0     0     0     4     0
     0     0     0     0     5
>> diag(ans)
ans =
     1
     2
     3
     4
     5

reshape has syntax reshape(M,a,b). It takes a matrix M that used to have x rows and y columns and turns it into a matrix with a rows and b columns. a*b must equal x*y for this to work.

Lesson 2: simple plotting

Syntax introduced:

plot line axis randn

plot(x,y) creates a figure window and plots the values of vector x on the x axis versus the values of vector y on the y axis. MATLAB defaults to a blue solid line connecting all the data points, but you can specify a range of linestyles, colors, and symbols. The vectors x and y need to be the same length.

If you want more than one dataset on the same axes, there are a few ways to do it. You can specify several pairs of vectors in the same plot command, you can type hold on in between plot commands, or you can use the line command for all subsequent plots after the first plot command. Note that line only takes two arguments (x and y values), so you can't use it if you want to plot discrete data points.

MATLAB defaults to adapting the axes ranges to the range of values in the vectors being plotted. To set specific axes ranges instead, use axis([xMin,xMax,yMin,yMax])

>> x=linspace(1,10);
>> y=randn(size(x));
>> z=y*.5;
>> plot(x,y,'r-','linewidth',2);
>> hold on;
>> plot(x,y,'ko','markerfacecolor','c');
>> line(x,z);
figure created when code snippet above is run
Figure created when code snippet above is run

In the code snippet that produces the plot above, here is an explanation in English. First I created a 100-point equally-spaced vector that went from 1 to 10. Then I used randn to make another vector with random entries that is the same length as the first vector. Then I made another vector the same length as the first two whose entries are all half the value of what they were in the second vector. The rest of the snippet is plotting. The line plot(x,y,'r-','linewidth',2); plots x vs. y with a red line two points wide. I use hold on so that the next plot command plots over the first one without clearing the plotting axes. The next plot command plots the same data as before, using a black circle that is filled with cyan. Then the line command plots x vs. z using a blue solid line that is the default. To look up the various colors, symbols, and linestyles do help plot inside the MATLAB command window.

Check yourself!

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 2 tasks!

You have reached the end of Lesson 2! Double-check the to-do list on the Lesson 2 Overview page [2] to make sure you have completed all of the activities listed there before you begin Lesson 3.

Lesson 3: Scripts and Functions

Overview

So far, everything we have learned how to do in MATLAB required typing in commands one by one on the command line. This is fine for testing things out, but, really, the whole point of computers is to make repetitive calculations quickly and accurately. As soon as you realize you want to run the same set of commands over again, it is time to write a script or a function so you can do it 100 times. In this lesson, we'll begin learning how to write functions and scripts. You want to be hard-working with the thinking, but lazy with the typing.

Learning Outcomes

By the end of this lesson, you should be able to:

  • write a script to display a table of data.
  • write a function with user inputs.
  • write a script to make a plot.
  • use MATLAB as a graphing calculator, also to display data.
Lesson Roadmap
To Read content on this web site here
To Do

Quiz

Canvas

Questions?

If you have questions, please feel free to post them to the Questions? discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 3: Script that displays data

Syntax introduced:

% clearvars disp

Write a simple script

A script, in any programming language, is a file containing a series of commands that are executed automatically in order as if you had typed them one by one. MATLAB  scripts end with the file extension ".m" In your MATLAB command screen there's a button that looks like a big yellow plus sign up in the toolbar labeled 'New.' If you click it, an Editor window will open up and your cursor will be in it, ready for you to type something.

Enter image and alt text here. No sizes!

You can also use the text editor of your choice to create a script. As long as the file you create has the right file extension and MATLAB knows where the file is located in your computer's file structure, you can run it. When I say "text editor of your choice" I do not mean a word processing program like Microsoft Word or Macintosh Pages. I mean a plain text editor like vi or emacs. If you don't know what I'm talking about, just use the built-in editor in MATLAB.

I wrote a short script to display a two-column table of data (below this paragraph). Copy and paste it into your editing window. Save the file. Name it sb.m. In order to run it, just type sb into the command line. Or you can hit the Run button in the MATLAB toolbar.

%display points scored by the first ten superbowl winners 
clearvars; 
yr=[1967 1968 1969 1970 1971 1972 1973 1974 1975 1976]; 
winnerPoints=[35 33 16 23 16 24 14 24 16 21]; 
tableYW(:,1)=yr'; 
tableYW(:,2)=winnerPoints'; 
disp('        YEAR       POINTS SCORED')
disp('                    BY WINNER')
disp(' ')
disp(tableYW) 

WebApps Note

If you are running MATLAB through webapps then copying and pasting is not so simple. This is what you do: Highlight and copy the chunk of text like you normally would. Then in your webapps tab, click the pink toolbox icon to expand it. Now click the clipboard icon from the toolbox dropdown. Follow the instructions there to put your copied text onto the clipboard. Once you close the clipboard, the paste-from-clipboard icon will now be available in the MATLAB window. Click that to paste the contents of the clipboard into your editing window inside MATLAB.

screenshot of MATLAB toolbar to show where the copy and paste icons are in webapps
Screenshot of MATLAB toolbar when MATLAB is running through webapps
Hopefully when you ran it, the output looked like:
>> sb
        YEAR       POINTS SCORED
                    BY WINNER
 
        1967          35
        1968          33
        1969          16
        1970          23
        1971          16
        1972          24
        1973          14
        1974          24
        1975          16
        1976          21

New Stuff in this Script

Comments

The first line of the script begins with %. That's a comment. MATLAB ignores it but you shouldn't. Comments are some of the most important parts of a program, no matter what language you use. I rank comments right up there with help and lookfor in the MATLAB Pantheon of What's Useful. Comments are handy for saying in plain language what your code does, reminding yourself where you got the data, temporarily not running a certain problematic line of code while debugging, and more. Single line comments are preceded by %. If you want to write more than one line you can either put a % at the beginning of each line or enclose the whole block inside a %{ %} pair.

Clearing and displaying variables

The next line of my script says clearvars which tells MATLAB to clear all the variables from the workspace. I'm in the habit of putting clearvars at the top of my scripts so I don't have to worry about introducing some unexpected error by using a variable name that is already there. The next lines create row vectors to house the data. Then I turn the row vectors into column vectors and make an array out of them. I use disp to tell MATLAB to show me the data on the screen. Using disp is about the same as leaving off the ; at the end of the line except MATLAB doesn't echo back the variable name. You can also use disp as I did to display the actual text of what you typed by putting the text inside single quotes ' '.

Efficiency v. Clarity

In my script above I did a couple of things that expert programmers hate. First of all, I typed in my data by hand. This is not good practice because it takes time and is a really obvious way to introduce clerical errors. A better approach would be to find the data somewhere, download a file of it and read that file in. We'll learn how to do that soon, so no worries there. The second thing is that I created two vectors, then a created a whole 'nother array out of my two vectors, so essentially I'm duplicating effort there. I could have written the program like this instead and eliminated two lines of code:
%display points scored by the first ten superbowl winners 
clearvars;  
tableYW(:,1)=[1967 1968 1969 1970 1971 1972 1973 1974 1975 1976]'; 
tableYW(:,2)=[35 33 16 23 16 24 14 24 16 21]'; 
disp('        YEAR       POINTS SCORED')
disp('                    BY WINNER')
disp(' ')
disp(tableYW) 
Sure, this is better. From a computation time point of view, there's not much difference since the program is so short in the first place. The main thing for you to think about here is whether you, upon reading this program, would understand what I had done here. Can you picture in your head the all-in-one step creation of a column vector of data as part of a larger array? If you can't, then you might prefer my original version even though it is not as terse. Someone will yell at me for giving this advice but I'm going to say it anyway: A program that works is sometimes better than the most elegant program, especially when you are first learning.

Check yourself!

Lesson 3: Script that makes a plot

Syntax introduced:

legend

Click the + in MATLAB's editor window to open up a new blank file. Copy and paste this simple script into your editor. Save it, name it something, then run it by typing its name into the command window.
% this is a test script. it makes a plot
x=0:.1:2*pi;
y=sin(x);
z=sin(2*x);
plot(x,y,x,z);
axis([0 2*pi -1 1]);
legend('sin(\theta)','sin(2\theta)');
plot of code snippet above. Two sin functions on the same axes.
Figure generated by script above.
E. Richardson, created with MATLAB

Explanation of the script

First I wrote a comment that says what the script does. Then I created a vector named x. Then I created two more vectors the same size as x that are functions of x. Next I used plot to plot both functions on the same axes. I set the axes limits, and then I made a legend to label both lines. legend is a new command. By default it correctly labels the plotting elements in the same order as you plot them in your script. Enclose any plain text in single quotes so MATLAB will render it as text. This works in the legend and also in axes labels and tick labels. Many special symbols such as Greek letters can be rendered by typing the word out with a backslash in front of it. The table below tells how to make some common special characters so they'll be rendered correctly on labels.

Creating special characters for plot labels in MATLAB
 SYMBOL AN EXAMPLE HOW TO TYPE IT
lowercase Greek letter α '\alpha'
uppercase Greek letter Γ '\Gamma'
degree 40.8° N '40.8\circ N'
superscript x2, ∂O18 'x^2', '\deltaO^{18}'
subscript H2SO4 'H_2SO_4'

Efficiency vs. Readability, take two

I could have saved a couple of lines in my script if I had just written:
% this is a test script. it makes a plot
x=0:.1:2*pi;
plot(x,sin(x),x,sin(2*x));
axis([0 2*pi -1 1]);
legend('sin(\theta)','sin(2\theta)');
MATLAB can do calculations within plot. But, even though the second example is shorter, it's my personal preference to do calculations and plotting as separate parts of my scripts. (This is probably a holdover from growing up with programming languages like C and FORTRAN in which you would do all your calculations there, and then pipe the output to a separate plotting package.) Nevertheless, I think separating data manipulation from plotting is not such a bad habit, especially once you get to more complicated programs. When you are working through difficult concepts, it is easier to isolate and fix mistakes if the math and/or science analysis is not wrapped up inside the choice of how to display the output, in my mind.

Lesson 3, Page 3

Lesson 3, Page 4

Lesson 3, Page 5

Lesson 3, Page 6

Lesson 3, Page 7

Lesson 3, Page 8

Lesson 3, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 3 tasks!

You have reached the end of Lesson 3! Double-check the to-do list on the Lesson 3 Overview page [3] to make sure you have completed all of the activities listed there before you begin Lesson 4.

 

Lesson 4: title

Overview

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • use fprintf.

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Lesson 4 Quiz
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 4, Page 1

sb
        YEAR   POINTS SCORED   POINTS SCORED
                BY WINNER        BY LOSER
 
        1967          35          10
        1968          33          14
        1969          16           7
        1970          23           7
        1971          16          13
        1972          24           3
        1973          14           7
        1974          24           7
        1975          16           6
        1976          21          17
        1977          32          14
        1978          27          10
        1979          35          31
        1980          13          19
        1981          27          10
        1982          26          21
        1983          27          17
        1984          38           9
        1985          38          16
        1986          46          10
        1987          39          20
        1988          42          10
        1989          20          16
        1990          55          10
        1991          20          19
        1992          37          24
        1993          52          17
        1994          30          13
        1995          49          26
        1996          27          17
        1997          35          21
        1998          31          24
        1999          34          19
        2000          23          16
        2001          34           7
        2002          20          17
        2003          48          21
        2004          32          29
        2005          24          21
        2006          21          10
        2007          29          17
        2008          17          14
        2009          27          23
        2010          31          17
        2011          31          25
        2012          21          17
        2013          34          31
        2014          43           8

sb
        YEAR   POINTS SCORED   POINTS SCORED
                BY WINNER        BY LOSER
 
        1967          35          10
        1968          33          14
        1969          16           7
        1970          23           7
        1971          16          13
        1972          24           3
        1973          14           7
        1974          24           7
        1975          16           6
        1976          21          17
        1977          32          14
        1978          27          10
        1979          35          31
        1980          13          19
        1981          27          10
        1982          26          21
        1983          27          17
        1984          38           9
        1985          38          16
        1986          46          10
        1987          39          20
        1988          42          10
        1989          20          16
        1990          55          10
        1991          20          19
        1992          37          24
        1993          52          17
        1994          30          13
        1995          49          26
        1996          27          17
        1997          35          21
        1998          31          24
        1999          34          19
        2000          23          16
        2001          34           7
        2002          20          17
        2003          48          21
        2004          32          29
        2005          24          21
        2006          21          10
        2007          29          17
        2008          17          14
        2009          27          23
        2010          31          17
        2011          31          25
        2012          21          17
        2013          34          31
        2014          43           8

sb
The Seahawks beat the Broncossb
The Seahawks beat the Broncos
and the game wasn't very close
sb
The Seahawks beat the Broncos
and they scored 43.000000 points
sb
The Seahawks beat the Broncos
and they scored 43 points
sb
The Seahawks beat the Broncos
and the score was 43 to 8
sb
In 1967 the score was 35 to 10
In 1968 the score was 33 to 14
In 1969 the score was 16 to 7
In 1970 the score was 23 to 7
In 1971 the score was 16 to 13
In 1972 the score was 24 to 3
In 1973 the score was 14 to 7
In 1974 the score was 24 to 7
In 1975 the score was 16 to 6
In 1976 the score was 21 to 17
In 1977 the score was 32 to 14
In 1978 the score was 27 to 10
In 1979 the score was 35 to 31
In 1980 the score was 13 to 19
In 1981 the score was 27 to 10
In 1982 the score was 26 to 21
In 1983 the score was 27 to 17
In 1984 the score was 38 to 9
In 1985 the score was 38 to 16
In 1986 the score was 46 to 10
In 1987 the score was 39 to 20
In 1988 the score was 42 to 10
In 1989 the score was 20 to 16
In 1990 the score was 55 to 10
In 1991 the score was 20 to 19
In 1992 the score was 37 to 24
In 1993 the score was 52 to 17
In 1994 the score was 30 to 13
In 1995 the score was 49 to 26
In 1996 the score was 27 to 17
In 1997 the score was 35 to 21
In 1998 the score was 31 to 24
In 1999 the score was 34 to 19
In 2000 the score was 23 to 16
In 2001 the score was 34 to 7
In 2002 the score was 20 to 17
In 2003 the score was 48 to 21
In 2004 the score was 32 to 29
In 2005 the score was 24 to 21
In 2006 the score was 21 to 10
In 2007 the score was 29 to 17
In 2008 the score was 17 to 14
In 2009 the score was 27 to 23
In 2010 the score was 31 to 17
In 2011 the score was 31 to 25
In 2012 the score was 21 to 17
In 2013 the score was 34 to 31
In 2014 the score was 43 to 8
sb
pwd

ans =

X:\

ls

.                         YSData.txt                
..                        bluefield-Table 1.csv     
._All_AftershockData.mat  bristol-Table 1.csv       
7506.txt                  burlington-Table 1.csv    
All_AftershockData.mat    catsearch_7464.txt        
KJData.txt                danville-Table 1.csv      
RTFData.txt               intraAftershock.txt       
SCECData.txt              
TPhaseData.txt            

coast = load('7506.txt');
{Error using <a href="matlab:helpUtils.errorDocCallback('load')" style="font-weight:bold">load</a>
Unknown text on line number 1 of ASCII file 7506.txt
" nan".
}
ls

.                     My Documents          
..                    WINDOWS               
.DS_Store             catsearch.16531       
.TemporaryItems       catsearch.16531.txt   
._.DS_Store           geosc444              
._.TemporaryItems     jan28Rennolds         
.portal               nmsz_19752005mag.txt  
20218.dat             sabr2014Fig1.jpg      
Downloads             test.jpg              
Favorites             

coast = load('20218.dat');
plot(coast(:,1),coast(:,2))
hold on;
plot(Lon,Lat);
hold off;
plot(coast(:,1),coast(:,2))
hold on
plot(Lon,Lat,'ko','markerfacecolor','k');
exit

Lesson 4, Page 2

Lesson 4, Page 3

Lesson 4, Page 4

Lesson 4, Page 5

Lesson 4, Page 6

Lesson 4, Page 7

Lesson 4, Page 8

Lesson 4, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 4 tasks!

You have reached the end of Lesson 4! Double-check the to-do list on the Lesson 4 Overview page [4] to make sure you have completed all of the activities listed there before you begin Lesson 5.

 

Lesson 5: Combine Scripts and Functions with File i/o

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • generate a plot from a function/script.
  • new command: datetick.
  • some general 'data literacy' knowledge.
  • functions with multiple inputs and outputs.

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Problem Set
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 5, Page 1

Lesson 5, Page 2

Lesson 5, Page 3

Lesson 5, Page 4

Lesson 5, Page 5

Lesson 5, Page 6

Lesson 5, Page 7

Lesson 5, Page 8

Lesson 5, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 5 tasks!

You have reached the end of Lesson 5! Double-check the to-do list on the Lesson 5 Overview page [5] to make sure you have completed all of the activities listed there before you begin Lesson 6.

 

Lesson 6: Logical Operators and Precedence

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • syntax: < > <= >= & ! |

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Lesson 6 Quiz
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 6, Page 1

Lesson 6, Page 2

Lesson 6, Page 3

Lesson 6, Page 4

Lesson 6, Page 5

Lesson 6, Page 6

Lesson 6, Page 7

Lesson 6, Page 8

Lesson 6, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 6 tasks!

You have reached the end of Lesson 6! Double-check the to-do list on the Lesson 6 Overview page [6] to make sure you have completed all of the activities listed there before you begin Lesson 7.

 

Lesson 7: Loops, Nested Loops

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • syntax: < > <= >= & ! |

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Problem Set
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 7, Page 1

Lesson 7, Page 2

Lesson 7, Page 3

Lesson 7, Page 4

Lesson 7, Page 5

Lesson 7, Page 6

Lesson 7, Page 7

Lesson 7, Page 8

Lesson 7, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 7 tasks!

You have reached the end of Lesson 7! Double-check the to-do list on the Lesson 7 Overview page [7] to make sure you have completed all of the activities listed there before you begin Lesson 8.

 

Lesson 8: Polynomials and Curve Fitting

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • syntax: polyval roots poly conv deconv polyder polyfit

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Lesson 8 Quiz
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 8, Page 1

Lesson 8, Page 2

Lesson 8, Page 3

Lesson 8, Page 4

Lesson 8, Page 5

Lesson 8, Page 6

Lesson 8, Page 7

Lesson 8, Page 8

Lesson 8, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 8 tasks!

You have reached the end of Lesson 8! Double-check the to-do list on the Lesson 8 Overview page [8] to make sure you have completed all of the activities listed there before you begin Lesson 9.

 

Lesson 9: More Matrix Manipulations and Plot Aesthetics

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • use figure handles instead of the gui to manipulate plot particulars.

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Problem Set
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 9, Page 1

Lesson 9, Page 2

Lesson 9, Page 3

Lesson 9, Page 4

Lesson 9, Page 5

Lesson 9, Page 6

Lesson 9, Page 7

Lesson 9, Page 8

Lesson 9, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 9 tasks!

You have reached the end of Lesson 9! Double-check the to-do list on the Lesson 9 Overview page [9] to make sure you have completed all of the activities listed there before you begin Lesson 10.

 

Lesson 10: More Loops, Histograms, Systems of Equations

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • use figure handles instead of the guide to manipulate plot particulars. 

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Lesson 10 Quiz
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 10, Page 1

Lesson 10, Page 2

Lesson 10, Page 3

Lesson 10, Page 4

Lesson 10, Page 5

Lesson 10, Page 6

Lesson 10, Page 7

Lesson 10, Page 8

Lesson 10, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 10 tasks!

You have reached the end of Lesson 10! Double-check the to-do list on the Lesson 10 Overview page [10] to make sure you have completed all of the activities listed there before you begin Lesson 11.

 

Lesson 11: title

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • explain ….
  • utilize….
  • evaluate….
  • Three to five goals of what the student will know or be able to do by the end of the lesson.

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Poblem Set
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 11, Page 1

Lesson 11, Page 2

Lesson 11, Page 3

Lesson 11, Page 4

Lesson 11, Page 5

Lesson 11, Page 6

Lesson 11, Page 7

Lesson 11, Page 8

Lesson 11, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 11 tasks!

You have reached the end of Lesson 11! Double-check the to-do list on the Lesson 11 Overview page [11] to make sure you have completed all of the activities listed there before you begin Lesson 12.

 

Lesson 12: title

Overview

Here’s where you will introduce your lesson. What will we learn, how does it connect with what we may have already covered, what can you expect content-wise?

Include the main topics of the lesson here. This can be included in the text or be a bulleted list.

Learning Outcomes

By the end of this lesson, you should be able to:

  • extend techniques covered in 9,10,11,12 with own dataset.

Lesson Roadmap

Lesson Roadmap
To Read List reading assignments Location
To Do
  • Capstone Formative/Rough Draft
  • Canvas

Questions?

If you prefer to use email:

If you have any questions, please send a message through Canvas. We will check daily to respond. If your question is one that is relevant to the entire class, we may respond to the entire class rather than individually.

If you prefer to use the discussion forums:

If you have questions, please feel free to post them to the General Questions and Discussion forum in Canvas. While you are there, feel free to post your own responses if you, too, are able to help a classmate.

Lesson 12, Page 1

Lesson 12, Page 2

Lesson 12, Page 3

Lesson 12, Page 4

Lesson 12, Page 5

Lesson 12, Page 6

Lesson 12, Page 7

Lesson 12, Page 8

Lesson 12, Page 9

Summary and Final Tasks

Summary

add summary here

Reminder - Complete all of the Lesson 12 tasks!

You have reached the end of Lesson 12! Double-check the to-do list on the Lesson 12 Overview page [12] to make sure you have completed all of the activities listed there.

 

H5P Play Space

H5P Sample 2

In this example I used the true/false template to ask a question. I used this instead of multiple choice because I don't think there is more than one obvious wrong answer in this question.

Here is an example of the drag and drop feature. It took me a while to get the hang of creating this because h5p intends for you to do this with images instead of blocks of text, but I made it work.

Quiz Mod

H5P Sample 1

Take a minute to answer the following question.

Add more text about something and add a new questions.

H5P Sample 3

I wanted to create an image hotspot question where you had to click on the right part of the image in response to a question, but I don't have permission to download h5p content and we don't have that one enabled right now.

H5P Sample 4


Source URL:https://www.e-education.psu.edu/geosc444/node/2

Links
[1] https://www.e-education.psu.edu/geosc444/3 [2] https://www.e-education.psu.edu/geosc444/6 [3] https://www.e-education.psu.edu/geosc444/517 [4] https://www.e-education.psu.edu/geosc444/524 [5] https://www.e-education.psu.edu/geosc444/525 [6] https://www.e-education.psu.edu/geosc444/526 [7] https://www.e-education.psu.edu/geosc444/527 [8] https://www.e-education.psu.edu/geosc444/694 [9] https://www.e-education.psu.edu/geosc444/695 [10] https://www.e-education.psu.edu/geosc444/696 [11] https://www.e-education.psu.edu/geosc444/697 [12] https://www.e-education.psu.edu/geosc444/698