Dr. Cavazos' Lecture Notes: Unix Commands, IF Statements, Arrays, Loops, and Functions, Study notes of Computer Science

This document, authored by dr. John cavazos from the university of delaware's computer and information sciences department, covers various topics including unix commands, if statements, arrays (or matrices), loops, scripts, and functions. The document also includes information about midterm review sessions and exams. Students are encouraged to study labs, write code for labs, and attend review sessions. Examples and explanations of unix commands, if statements, arrays, and loops, as well as an introduction to functions.

Typology: Study notes

Pre 2010

Uploaded on 09/02/2009

koofers-user-sym
koofers-user-sym 🇺🇸

10 documents

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dr. John Cavazos
Computer and Information Sciences
03/16/2009
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Dr. Cavazos' Lecture Notes: Unix Commands, IF Statements, Arrays, Loops, and Functions and more Study notes Computer Science in PDF only on Docsity!

Dr. John Cavazos Computer and Information Sciences 03/16/

 Unix commands  if statements  arrays (or matrices)  loops  scripts  functions

 Write code from memory  Study labs ◦ Write code for labs  Study Midterm review  Attend review session

 When you log into a UNIX terminal ◦ You are in your home directory. ◦ To see the files in your directory.  ls ◦ To make an new folder/directory.  mkdir exampledir ◦ To change directories.  cd exampledir ◦ To go back one directory.  cd .. ◦ To go back to your home directory.  cd

if (expression1)

statements1;

elseif (expression2)

statements2;

else

statements3;

end

◦ A < B A is less than B ◦ A > B A is greater than B ◦ A <= B A is less than or equal to B ◦ A >= B A is greater than or equal to B ◦ A == B A is equal to B ◦ A ~= B A not equal B

if (N <= 5) fprintf 'blue\n'; end if (N > 5 & N <= 10) fprintf 'red\n'; end if (N > 10) fprintf 'green\n'; end

 All variables in matlab are arrays  An array of one element is called a scalar  A one dimension array is called a vector x=3.14;  scalar a = [1,2,3,4,5];  vector

 A = [1, 2; 3, 4; 5, 6]

 Creates a 3x2 array, 3 rows, 2 columns.  semicolon creates a new row.

A = 1 2

 Used when you know how many times code is to be executed.  Syntax for = ::  Variable is initially the start value  At end of iteration variable changes by increment  If value is not greater than end the loop runs again.

 total = 0; for i = 1:1:1000 loop starts at 1 total = total+widget (i); loop increments by 1 end loop ends at 1000 avg = total / 1000;

 The mail man/woman executes a loop.  If they know the number of deliveries  For loop for delivery = start : next_delivery : end deliver_mail(delivery) end

sumIt=0; for current=1:finish if (mod(current,2)==1) sumIt=sumIt+current; end end

 Special type of m-file ◦ Function name same as file name  Contains a function name, arguments, output, and “implementation”  All variables in function are local ◦ They are not visible outside call!