ENGR101 Lab1: Submission Requirements
ENGR101 Lab1: Submission Requirements
Submission Requirements:
All labs are due at 11:59pm the day after your lab section. See Part 2 of this lab on how to
submit these files.
Now try entering the following into the command prompt and you should see your first MATLAB
error.
>> 21 = Sarah
MATLAB doesnt know how to interpret your command and thus shows an error. Remember: =
is the assignment operator. It does not act like the equals sign in algebra. Instead, it assigns a
value on its right to a variable on its left. Since 21 is a scalar value that cannot be assigned,
MATLAB gets upset.
Some variables are built-in. You can use these like any other variables, but be careful: you can
also overwrite these variables.
>> pi
>> pi = 2
Strings
MATLAB isnt just for numbers. You can use letters and words in your programs too. In
computer terms, we like to call letters characters and words strings. (you can remember
them as a string of characters)
>> a = a
>> phrase = Hello World!
Notice that we use single quotes so that MATLAB knows the difference between variable
names and characters/strings.
Finally, lets go ahead and erase any indication that you did this tutorial:
>> clc
This command will clear the command window, leaving you with what looks like a blank slate to
program on. However, type the following:
>> phrase
The variable you created earlier is still there! You can also see it and all other variables in the
Workspace. Lets just tell MATLAB to clear that evidence.
>> clear
Voila! This clears all the variables from MATLAB its like restarting MATLAB.
MATLAB Scripts:
Command line programming isnt a particularly feasible way to complete your projects. What if
you mess up the 50th line and have to start over by typing 1-49 in again? What are you going to
turn in? To avoid those problems, we use scripts. Scripts are just files containing lines to be
executed in a given order. You should have seen how to create these in the pre-class video. If
you dont know or remember, please ask someone near you!
Comments:
When youre writing programs, its nice to make notes in your programs. These notes should be
lines that are not interpreted by MATLAB. Instead, they help human readers understand what
youre trying to accomplish in your program. Comments are lines that begin with the percent
character (%).
Exercise 2:
Download lab1_2.txt and answer the questions within it. You can use any editor youd like to edit
the text file. Even the MATLAB script editor can work! Just make sure to place it in your lab1
folder to keep everything organized.