















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
















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
◦ 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
Creates a 3x2 array, 3 rows, 2 columns. semicolon creates a new row.
Used when you know how many times code is to be executed. Syntax for
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!