0% found this document useful (0 votes)
49 views

ENGR101 Lab1: Submission Requirements

This document summarizes the instructions for Lab 1 of the ENGR101 course. It includes two parts and two exercises. Part 1 discusses getting started with MATLAB, including how to log in to the CAEN machines, create folders and variables in MATLAB. Part 2 explains how to submit assignments by saving files as instructed and uploading them to Canvas. Exercise 1 has students complete a MATLAB script by filling in missing lines. Exercise 2 involves answering questions in a text file about using the online forum Piazza.

Uploaded by

William Tuten
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

ENGR101 Lab1: Submission Requirements

This document summarizes the instructions for Lab 1 of the ENGR101 course. It includes two parts and two exercises. Part 1 discusses getting started with MATLAB, including how to log in to the CAEN machines, create folders and variables in MATLAB. Part 2 explains how to submit assignments by saving files as instructed and uploading them to Canvas. Exercise 1 has students complete a MATLAB script by filling in missing lines. Exercise 2 involves answering questions in a text file about using the online forum Piazza.

Uploaded by

William Tuten
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ENGR101 Lab1

Part 1: Getting Started with MATLAB


Part 2: Turning in Assignments
Exercise 1
Exercise 2

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.

Exercise 1: Save your work as lab1_1.m


Exercise 2: Save your work as lab1_2.txt

Part 1: Getting Started with MATLAB


Prior Knowledge:
Prior to this lab, you should have completed Lab 0 and watched the MATLAB tutorial video. The
rest of this lab is written expecting you to have learned the following. If you cannot remember or
have questions on these points, please review Lab 0 or ask your instructor before getting
started with the lab.

Logging into Windows on a CAEN machine (recap in next section)


Opening MATLAB on a CAEN machine (recap in next section)
Navigating MATLAB
Command Window
Workspace
Current Folder
Script Editor
Assigning variables
Suppressing output with semicolons

Opening MATLAB on a CAEN Machine


As most of you are likely new to CAEN computers, lets take a brief minute to recap how to log
into Windows and open MATLAB. If youre already familiar with this process, feel free to skip to
the next section. Talk to those around you or ask the GSI if you get stuck.
1. Verify that the machine is booted into Windows
a. If the machine isnt booted into Windows, restart the machine and
select the Windows icon in the boot prompt
2. Log into Windows using your uniqname and password
a. You should have verified a working CAEN account in Lab 0

3. Shortly after login, a browser window should appear with


https://software.engin.umich.edu in the address bar
4. Scroll down until you see an entry labelled: MATLAB 64-bit R2016a (Student
Instructional License)
5. Click the green Launch button corresponding to this entry
a. Sometimes this will cause the page to refresh and display that its
validating the session. If this happens, wait for validation to finish and repeat
steps 4 & 5
6. You should see the application loading in the Cloudpaging Player program. Once
the status is set to Ready, select the MATLAB entry and click the Launch button at
the top
7. MATLAB will now launch (may take a minute)

Creating an 101 Directory


1.
2.
3.
4.
5.

Navigate to your desktop in Windows


Right click on an empty space on the desktop
Select NewFolder
Name this folder engr101
Open this folder and create a new folder called lab
a. This will be the base directory for all your lab files

Creating Variables in MATLAB:


From now on, when you see >>, type the following line into the command prompt. Make sure to
pay attention to what each individual line is doing. Note that most lines DO NOT include
semicolons so that you can easily see your work.
You have seen in the video how easy it is to create variables that show up in the Workspace.
So far, weve created scalar variables (variables with single values).
>> person = 0
>> Person = 12
>> Sarah = 21
>> Person = Sarah
Notice that Sarah doesnt actually mean the word Sarah, its a variable that
currently holds the value 21.
>> Sarah = 56
In this example, each variable is assigned its own value. Make sure you can identify the
Workspace and you can see these variables in that window. If you cant, ask your GSI or
someone around you. Notice in the Workspace that person and Person are two separate
variables with two different values. This is because variable names are case sensitive.
Additionally, Person first has the value of 12 but then is reassigned to Sarahs value (21).
However, these values are not linked in any way: the value 21 is copied and then stored in the
variable Person. When Sarah is reassigned to 56, the value of Person remains 21.

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 (%).

Part 2: Turning in Your Assignments


Labs must be turned in through the relevant assignment in Canvas > Assignments. Be sure to
submit all files listed under Submission Requirements.
The name of your files must be exactly as specified in order to receive credit.

Exercise 1: Getting to Know Matlab


Complete the following. If you dont know how to do any steps, go ahead and ask your neighbor.
1. Download the lab1_1.m file from Google Drive where you found this lab.
2. Create a lab1 folder in your engr101\lab folder and place lab1_1.m into this
folder.
3. Navigate your Current Folder to your engr101\lab\lab1 folder. You should see
lab1_1.m in the list of files.
4. Complete the program by reading the comments and filling in the missing lines.
5. Run your script by typing the following into the Command Window.
>> lab1_1
6. Test your script with different values of the Seed and make sure you get the
following values.
a. Seed = 2 apple = 4, Banana = 7, carrot = 4,
dragonFruit = 350
b. Seed = 50 apple = -20, Banana = -1, carrot = 0,
dragonFruit = 22
7. Navigate your Current Folder up one directory to your engr101 folder by clicking
the following button.

8. Run your script again.


>> lab1_1
This step should result in an error. This is because the script you are trying
to run is not in your Current Folder. MATLAB doesnt know what youre
talking about when you say lab1_1.
9. Right click on your lab folder and click Add to Path. Now try running the script
again. This works because now MATLAB knows another place to look for something
called lab1_1.

Exercise 2: Getting to Know Piazza


Piazza is our online forum. Its a useful resource for you to get help from instructors and your
fellow students. We have compiled an etiquette document to help you use Piazza responsibly
which you can find on Canvas under the Piazza tab.

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.

You might also like