Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia

Size: px
Start display at page:

Download "Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia"

Transcription

1 Matlab for FMRI Module 1: the basics Instructor: Luis Hernandez-Garcia The goal for this tutorial is to make sure that you understand a few key concepts related to programming, and that you know the basics of the Matlab language. You don t need to turn anything in, just read through this document and execute the code that is provided. As you run through it, please ask an instructor or a classmate if anything doesn t make sense. Note that some of the commands that you will type will cause errors. Don t panic - this is intended for illustration purposes and to make you think about what happened. Exercise 1 Familiarize yourself with the GUI The first thing I would like you to do is to spend a little bit of time becoming acquainted with the Matlab interface, if you haven t before. Please locate the following items and make sure you know what they are for (there is nothing to answer, just check them off as you go: - The current directory dropdown menu - The view of the current directory contents - The workspace window - The command window - The command history window Next, let s have a look at the menus on the top of the interface. Find the following - The Set Path command (it s under the File menu) - The Editor command (it s under the Desktop menu) The next thing to note is that there is a lot of documentation available. The most frequent situation happens when you come across a command and you don t quite remember how it worked. In that case you type in the command line: help command_in_question For example: help plot 2 The Directory Structure and Matlab Matlab is a programming language and environment. As such, its job is to execute commands and manage information in the computer s memory and in the hard drive. When you are in matlab, whatever you do - execute commands, access data... etc, happens in a specific location in the file system (a.k.a. the directory tree). You can move up and down the directory tree using the Current Directory drop down menu. If you are working in the command window, the command "cd" (change directory) does the same thing to navigate the file system. The command "pwd" tells you where you are.

2 Try these on the command window and notice what happens (you don't need to write anything) cd C:\fMRI_Course\fMRI_lab\LabAssignments\ pwd Now do the same thing using the same thing from the user interface: use the drop down menu to go to the same directory. Please feel free to play around and move around the directory tree. 3 Matrices Matlab works with matrices (that s why it s called MATlab). It doesn t really know how to do anything else, so it treats almost everything as matrices or collections or matrices. All variables are considered to be matrices. As you will soon see, it even deals with text as matrices. Try a few basic commands. Type each of these lines in and observe what happens in both the command windows and the workspace window (again, no need to write anything, just check them off as you go) a = 1 a whos a Note what happens with the semicolon at the end (it suppresses the output to the screen you will want this when you have big matrices) a = 1; Let's make a matrix by hand: a = [1 2 3 ; ; 7 8 9; ] Now that we have a matrix, let's get a sense for how the data is stored and accessed within the matrix. Please pay close attention to the patterns and make a note of what each line gives you back. a(1) a(1,3) a(:,2) a(2,:) a(:) a(2:end, :) So now you see how you can access the different elements, rows, and columns of a matrix. Next, let s try doing things to matrices, i.e. changing their values, and doing operations on them: The "whos" command tells you the dimensions of the matrix. It's very useful when you have errors. a' a = [1:3:100] whos a Transposing a matrix: b = a' a = a' whos a (Warning: the quotes should always be single FORWARD quotes. The backward quotes are trouble!)

3 Remember, everything is a matrix in matlab so the operations are by default matrix operations!! Watch out for that. It takes a little getting used to. Let s play a little with matrix operations. Start out by making some matrices to operate on, then try some of basic operations and notice which ones work and which ones give you an error. a = [ 9 8 7; 3 2 1] b = [ 1 2 ; 4 5 ; 7 8 ] c = a * b c = a * b' c = 7 * a; So, as you can see, all the rules about multiplying matrices apply. On the other hand, this is how you do element by element multiplication and division (note that "*" is not the same as ".*" ) c = a.* b c = a.* b' Here are a few more practice exercises designed to get you used to matrices and their operations c = a * b; whos a b c = a' * b ; whos c c = a * b'; whos c Let s now look at how text is handled. If you want to set a variable to a string (a bunch of characters), you need to put them in quotes. If you don t, Matlab will think that these characters are some variable in your workspace. For example: a = 'some text... ' b = 'more text' (note, make sure they are single FORWARD quotes around the string too) c = [ a b] c = a + 10 c = a' *b Can you explain what happened with those strings? Here is a hint. Type the command double(a) Let s finish this exercise by removing the data from memory. Matlab can delete data from memory with the clear command. Type the following commands and note what happens. who clear b c whos clear all whos

4 4 Making graphs and displaying images with Matlab Matlab is extremely useful for displaying data. It can do all kinds of 2D, 3D plots, surface, contour plots, surface renderings, bar graphs you name it. Let's look at some basics by typing the following lines and noting what Matlab does in response. a = [0:0.1:3*pi]; figure plot(a) figure plot(sin(a)) figure plot(a, sin(a)) figure a = phantom; imagesc(a) colorbar colormap gray Note all the different menus you get on the figure itself. Now, find how to store the figure as a JPG image from the figure. When you want to get rid of a figure you use these close or if you want to get rid of all your figures, then you do this: close all 5. Storing and retrieving data from disk Matlab can read and write a variety of file formats, but right now we re just going to focus on a couple of them. Matlab is designed to work with data files that have a.mat extension. These are binary files that contain matrices. You can load a.mat file using the command load and you can save your matrices by using the command save. As an example, we have provided you with a couple of files to play with. Try this load( C:\fMRI_Course\fMRI_Lab\LabAssignments\Lab1_Matlab\data\SPM_fMRIDesMtx. mat ) you ll note that you specified the whole path to the file. But, you could also navigate (i.e., use the CD command) your way to the directory where the file lives and THEN do this: load('spm_fmridesmtx.mat') Now create your own.mat files. Try these and see what you get: save myvariables.mat (That saves everything in your workspace into a file. Check to see that you created the file with the ls command or just look with the file manager)

5 save somevariables.mat a b (That saves only the variables a and b) Those.mat files are in a special binary format and it takes some effort to decode outside of matlab, but If you want to create a quick text file to read in excel (or whatever) you can also do it with the save command, like this: save mytextfile.txt a -ascii You can open mytextfile.txt with notepad and look at its contents. You ll see it s just plain text. 6. Scripts and the path The concept of scripts is simple. They are nothing but a whole bunch of commands that have been copied to a text file, so that in the future you can execute them over and over without having to type them again individually. Instead of typing the commands one at a time, you can just execute the script and it will in turn execute all the lines in the order in which they are typed. There are two ways to execute a script: You can run a script from the command line or you can run it by opening up the Matlab editor and pressing the Execute button. Let s try an example of a script by opening the Matlab Editor window (you can do this from the command line by typing edit ). Now open a New blank.m file and copy a few commands from the above exercises into that file. When you are done, save the file in the C:\fMRI_Course\fMRI_Lab\LabAssignments\Lab1_Matlab directory with the name my_script_01.m Next, execute the script by typing in the command line my_script_01 VERY IMPORTANT NOTE: check your Current Directory. Is it C:\fMRI_Course\fMRI_Lab\LabAssignments\Lab1_Matlab? If it is not, Matlab will not know what to do and will give you an error. Why is that? The reason for this behavior is that Matlab is programmed so that when you type a command at the command line, it loads the command (script or function) into memory, translates it to machine language and THEN executes the instructions. Thus, the first thing that Matlab needs to know is where that command is saved. The first place it checks for the file containing the command/script/function is the current working directory. Matlab asks itself is there a my_script_01.m file at the current working directory?. If not, then it looks through a specific list of directories, called the path, and checks to see if the script (or function) is there. The last place that Matlab checks for a command is the native Matlab libraries that get loaded into memory when you start it up. This path is the list of directories where Matlab checks for programs and scripts. It is really

6 important and you should configure it so that Matlab knows where to find YOUR programs. Let s set your path now: Use the Set Path command (it s under the File menu). All you have to do is choose the directories you want to add to the path and hit the add folder button. You ll notice that the order matters. In other words, if there is a command that exists in two separate directories on the path, matlab will execute the first one that it finds. If you want to know the location of the script that Matlab will execute use the command which. For example: which my_script_01 Note: This sort of PATH concept is very common in all operating systems and computer languages It s likely that you already know about paths. It is very useful for two reasons. First, because it gives you control over what version of code gets executed and by whom. It would also be very impractical to have Matlab check the entire disk for programs every time it wants to run something. It would also be very impractical to have to write the whole location of the program every time you want to execute it. I just showed you how to set the path from the GUI. You can also do the same thing by typing this in the command line: addpath C:\fMRI_Course\fMRI_Lab\LabAssignments\Lab1_Matlab In fact, this second way of doing it is much more convenient and you are a lot less likely to make a mistake. So, let s do it that way from now on. 7. Functions In Matlab, functions work a lot like scripts: a nice text file with a bunch of commands in it that you call from the command window. BUT, there are some important features that make a function different from a script, though. The most important difference is that a script has access to all the variables that you have in the workspace and a function does not unless you specify that some variables go into the function. The workspace will have access to all the variables that you created in a script, but not the ones you created inside a function unless you specify that those specific variables be returned. In math, a function is some sort of manipulation to some numbers (input) that produces a result (an output). Programming functions works very much the same way. A function is a bunch of operations (commands) that work on a set of input variables and return a result. But that is where the similarity ends. Unlike Math functions, a Matlab function may do a bunch of stuff that has nothing to do with math, like moving files around, making figures etc. Another difference is that the number of inputs and outputs can be very flexible. The code of a function has a number of key features. The most important things to remember are: 1. The first line in a function has this format (below). This is usually called the declaration of the function. The first line of the file specifies the inputs and outputs of the function, like this: function result = function_name( input1, input2, etc.) 2. When a function is being executed, Matlab ignores all the variables previously in the workspace. It is as if a fresh new Matlab were started, and the only variables that matter are the ones INSIDE that function s code. So if you want to use any variables inside that function, you need to pass them as inputs to the function. Let s look at an example. First make your own function by typing (well copying and pasting) the following lines into a document in the Editor window: function y = add_noise( indata, noise_level )

7 % function y=add_noise( indata, noise_level ) % % This function will take whatever input data and foul it up by % adding gaussian noise to it. % % inputs: % indata: the data that will receive the noise % noise_level: a multiplicative function to determine how much noise to add % the_noise = noise_level * randn(size(indata)); y = indata + the_noise; plot(indata); hold on plot(y,'r') legend('original Data', 'Noisy Data'); hold off return First, spend some time staring at that code and try to figure out what each line does. Feel free to ask questions. Now call the function from the command line, as follows: t=[0:0.01:3*pi] x = sin(t); nd = add_noise(x, 0.2) 8. Structures A structure is a useful construct to group related data together in an organized way. For instance, we can group different data related to a single subject as a structure. This way when we need to do something with that subject, everything about that subject is easily accessible and you can do everything in one shot. Let s look at a toy example. Let s say that you are analyzing data from subjects, and each individual subject has a bunch of stuff you want to track, like their heart rate, their occupation, their hobbies whatever. This first line defines what things this subject structure should contain. It also puts default values into those elements: subject=struct('profession','professor','hobby','golf','heart_rate',200,'num_ students',15, 'EEG', randn(12,1000)) You could also make a structure by typing this directly: subject.profession='professor'; subject.hobby='golf'; subject.heart_rate= 200; subject.eeg = randn(12,1000); Now, when you want to access the data in the structure, you can access the individual data fields like this: subject.hobby If you have a bunch of subjects with the same sort of data, it may simplify things a lot if each subject is

8 treated as a structure. Matlab will let you create arrays of such subjects. This is a really nice way to keep your data grouped and organized. Something like this: subject(1).profession='professor'; subject(1).hobby='golf'; subject(1).heart_rate= 200; subject(1).eeg = randn(1000,3); subject(2).profession='accountant'; subject(2).hobby='dog sledding'; subject(2).heart_rate= 30; subject(2).eeg = randn(1000,3); etc Now that your data is grouped so nicely, then you could have a function that analyzes each subject s data. For example, let s say that you name your function perform_my_brilliant_analysis.m. You would pass all the info into the function like this: answer = perform_my_brilliant_analysis( subject(2) ) And the function would use the different fields in the structure to calculate well whatever it is that you want to calculate with the heart rate, EEG, and hobby.? If this seems odd now, in a couple of days, we ll see how this is also very useful to keep track of fmri images and image headers. 9. Loops We use computers to carry out calculations that we have to do over and over and over and over. This is particularly true in image data, where we do the same exact things to each of many thousands of pixels. This is one place where loops come in very handy. Loops exist in all programming languages. The basic idea is that there is a segment of the code that gets repeated as some sort of counter keeps incrementing (or decrementing). In Matlab, the loop is a bunch of commands sandwiched between a for command and an end command Example. Type this code into an editor window and execute it. Note what happens. % make a nice phantom to play with and display it im = phantom(100); subplot(211) imagesc(im) colormap gray % now make a second one with zeros in it im2 = zeros(size(im)); % at each pixel location (x,y) stick in the % weighted average of its neighbors: for x=2:99 for y=2:99 im2(x,y) = ( im(x, y) +... im(x-1, y-1) +...

9 end end im(x+1, y+1) +... im(x+1, y-1) +... im(x-1, y+1) ) /5; % display the result of the operations. This results in a blurring of % the image (or smoothing it, which sounds a lot better!) subplot(212) imagesc(im2) First, spend some time staring at that code and try to figure out what each line does. Feel free to ask questions. Can you identify the structure of the loop? What are the variables that are changing? What is staying the same? Can you modify the code so that you only blur the center of the image? 10. IF statements The last fundamental command that we ll cover is the IF statement. When the matlab interpreter finds the keyword if, it evaluates whatever comes next, and if it is true, then continues executing the next lines. If it s not true, though, Matlab skips the following lines until it finds an end statement. For example, copy and paste this into the editor and execute as a script: a = 1; if a==1 fprintf('\nyes!! a is equal to 1! Hooray!!! ') end fprintf('\nthis script is sadly over') Questions: Did you notice the use of == instead of =? Do you know why that is? The two mean different things. How about that fprintf statement? Do a help and read what it says about it. fprintf is really handy. If you can t figure it out on your own, please ask for help. Let s try one last example combining the IF statement with the FOR loop. Take this code and put it into a script. Execute it and note it s behavior. Can you figure out what the script does before executing it? % make a nice phantom to play with and display it im = phantom(100); % let's add a little noise to it im = im *randn(size(im)); subplot(211) imagesc(im) colormap gray colorbar % now make a second one with zeros in it im2 = zeros(size(im)); % this is a very simple edge detector.

10 % at each pixel location (x,y) stick in the value of a % weighted average of its neighbors: for x=2:99 for y=2:99 noise = randn(1); % make the calculation only for those pixels that have a large % enough value. if abs(im(x,y))>0.05 im2(x,y) = ( 4*im(x, y) -... im(x-1, y-1) -... im(x+1, y+1) -... im(x+1, y-1) -... im(x-1, y+1) ); end end end % display the result of the operations subplot(212) imagesc(im2) colorbar Now change the values in the script, just for fun. What if you replace the value 0.05 for something else in this line of the code? if abs(im(x,y))>0.05 For extra credit, look up the commands else and case. We re not going to use them in this tutorial, but I would like for you to be aware of how the IF structure can be expanded to handle more than two choices. 11. End of First Tutorial There is a lot more to Matlab than what we ve covered today, obviously, but I hope that these few concepts will serve as a review of the basics and will get you started on your way to becoming a programmer. In the next couple of days we ll look at some very specific applications.

MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

More information

APPM 2460 Matlab Basics

APPM 2460 Matlab Basics APPM 2460 Matlab Basics 1 Introduction In this lab we ll get acquainted with the basics of Matlab. This will be review if you ve done any sort of programming before; the goal here is to get everyone on

More information

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB. MATLAB Introduction This guide is intended to help you start, set up and understand the formatting of MATLAB before beginning to code. For a detailed guide to programming in MATLAB, read the MATLAB Tutorial

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Introduction: MATLAB is a powerful high level scripting language that is optimized for mathematical analysis, simulation, and visualization. You can interactively solve problems

More information

Finding MATLAB on CAEDM Computers

Finding MATLAB on CAEDM Computers Lab #1: Introduction to MATLAB Due Tuesday 5/7 at noon This guide is intended to help you start, set up and understand the formatting of MATLAB before beginning to code. For a detailed guide to programming

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB The Desktop When you start MATLAB, the desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following

More information

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

CSE/NEUBEH 528 Homework 0: Introduction to Matlab CSE/NEUBEH 528 Homework 0: Introduction to Matlab (Practice only: Do not turn in) Okay, let s begin! Open Matlab by double-clicking the Matlab icon (on MS Windows systems) or typing matlab at the prompt

More information

Spectroscopic Analysis: Peak Detector

Spectroscopic Analysis: Peak Detector Electronics and Instrumentation Laboratory Sacramento State Physics Department Spectroscopic Analysis: Peak Detector Purpose: The purpose of this experiment is a common sort of experiment in spectroscopy.

More information

GLY Geostatistics Fall Lecture 2 Introduction to the Basics of MATLAB. Command Window & Environment

GLY Geostatistics Fall Lecture 2 Introduction to the Basics of MATLAB. Command Window & Environment GLY 6932 - Geostatistics Fall 2011 Lecture 2 Introduction to the Basics of MATLAB MATLAB is a contraction of Matrix Laboratory, and as you'll soon see, matrices are fundamental to everything in the MATLAB

More information

Lab 1 Introduction to MATLAB and Scripts

Lab 1 Introduction to MATLAB and Scripts Lab 1 Introduction to MATLAB and Scripts EE 235: Continuous-Time Linear Systems Department of Electrical Engineering University of Washington The development of these labs was originally supported by the

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

CS1114 Section 8: The Fourier Transform March 13th, 2013

CS1114 Section 8: The Fourier Transform March 13th, 2013 CS1114 Section 8: The Fourier Transform March 13th, 2013 http://xkcd.com/26 Today you will learn about an extremely useful tool in image processing called the Fourier transform, and along the way get more

More information

Lab: Supplying Inputs to Programs

Lab: Supplying Inputs to Programs Steven Zeil May 25, 2013 Contents 1 Running the Program 2 2 Supplying Standard Input 4 3 Command Line Parameters 4 1 In this lab, we will look at some of the different ways that basic I/O information can

More information

QUICK EXCEL TUTORIAL. The Very Basics

QUICK EXCEL TUTORIAL. The Very Basics QUICK EXCEL TUTORIAL The Very Basics You Are Here. Titles & Column Headers Merging Cells Text Alignment When we work on spread sheets we often need to have a title and/or header clearly visible. Merge

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Will Fox 25 September, 2006 Contents: 1) Interacting with Matlab 2) Arrays, aka Vectors 3) Thinking in Matlab vectorized indexing 4) Thinking in Matlab vectorized math 5) Thinking

More information

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING Objectives: B35SD2 Matlab tutorial 1 MATLAB BASICS Matlab is a very powerful, high level language, It is also very easy to use.

More information

Getting started with Matlab: Outline

Getting started with Matlab: Outline Getting started with Matlab: Outline What, where and why of matlab. The matlab desktop and you Entering commands Variables and data types Plotting 101 Saving and loading data A real world example What

More information

ECE 3793 Matlab Project 1

ECE 3793 Matlab Project 1 ECE 3793 Matlab Project 1 Spring 2017 Dr. Havlicek DUE: 02/04/2017, 11:59 PM Introduction: You will need to use Matlab to complete this assignment. So the first thing you need to do is figure out how you

More information

Getting started with MATLAB

Getting started with MATLAB Getting started with MATLAB You can work through this tutorial in the computer classes over the first 2 weeks, or in your own time. The Farber and Goldfarb computer classrooms have working Matlab, but

More information

How to program with Matlab (PART 1/3)

How to program with Matlab (PART 1/3) Programming course 1 09/12/2013 Martin SZINTE How to program with Matlab (PART 1/3) Plan 0. Setup of Matlab. 1. Matlab: the software interface. - Command window - Command history - Section help - Current

More information

MATLAB Introductory Course Computer Exercise Session

MATLAB Introductory Course Computer Exercise Session MATLAB Introductory Course Computer Exercise Session This course is a basic introduction for students that did not use MATLAB before. The solutions will not be collected. Work through the course within

More information

EOSC 352 MATLAB Review

EOSC 352 MATLAB Review EOSC 352 MATLAB Review To use MATLAB, you can either (1) type commands in the window (i.e., at the command line ) or (2) type in the name of a file you have made, whose name ends in.m and which contains

More information

Lastly, in case you don t already know this, and don t have Excel on your computers, you can get it for free through IT s website under software.

Lastly, in case you don t already know this, and don t have Excel on your computers, you can get it for free through IT s website under software. Welcome to Basic Excel, presented by STEM Gateway as part of the Essential Academic Skills Enhancement, or EASE, workshop series. Before we begin, I want to make sure we are clear that this is by no means

More information

Interactive MATLAB use. Often, many steps are needed. Automated data processing is common in Earth science! only good if problem is simple

Interactive MATLAB use. Often, many steps are needed. Automated data processing is common in Earth science! only good if problem is simple Chapter 2 Interactive MATLAB use only good if problem is simple Often, many steps are needed We also want to be able to automate repeated tasks Automated data processing is common in Earth science! Automated

More information

A quick Matlab tutorial

A quick Matlab tutorial A quick Matlab tutorial Michael Robinson 1 Introduction In this course, we will be using MATLAB for computer-based matrix computations. MATLAB is a programming language/environment that provides easy access

More information

Introduction to MATLAB

Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming

More information

UV Mapping to avoid texture flaws and enable proper shading

UV Mapping to avoid texture flaws and enable proper shading UV Mapping to avoid texture flaws and enable proper shading Foreword: Throughout this tutorial I am going to be using Maya s built in UV Mapping utility, which I am going to base my projections on individual

More information

You just told Matlab to create two strings of letters 'I have no idea what I m doing' and to name those strings str1 and str2.

You just told Matlab to create two strings of letters 'I have no idea what I m doing' and to name those strings str1 and str2. Chapter 2: Strings and Vectors str1 = 'this is all new to me' str2='i have no clue what I am doing' str1 = this is all new to me str2 = I have no clue what I am doing You just told Matlab to create two

More information

Introduction. Matlab for Psychologists. Overview. Coding v. button clicking. Hello, nice to meet you. Variables

Introduction. Matlab for Psychologists. Overview. Coding v. button clicking. Hello, nice to meet you. Variables Introduction Matlab for Psychologists Matlab is a language Simple rules for grammar Learn by using them There are many different ways to do each task Don t start from scratch - build on what other people

More information

Yup, left blank on purpose. You can use it to draw whatever you want :-)

Yup, left blank on purpose. You can use it to draw whatever you want :-) Yup, left blank on purpose. You can use it to draw whatever you want :-) Chapter 1 The task I have assigned myself is not an easy one; teach C.O.F.F.E.E. Not the beverage of course, but the scripting language

More information

Part 6b: The effect of scale on raster calculations mean local relief and slope

Part 6b: The effect of scale on raster calculations mean local relief and slope Part 6b: The effect of scale on raster calculations mean local relief and slope Due: Be done with this section by class on Monday 10 Oct. Tasks: Calculate slope for three rasters and produce a decent looking

More information

EGR 111 Introduction to MATLAB

EGR 111 Introduction to MATLAB EGR 111 Introduction to MATLAB This lab introduces the MATLAB help facility, shows how MATLAB TM, which stands for MATrix LABoratory, can be used as an advanced calculator. This lab also introduces assignment

More information

Writing MATLAB Programs

Writing MATLAB Programs Outlines September 14, 2004 Outlines Part I: Review of Previous Lecture Part II: Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Control Structures If/Then/Else For Loops

More information

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window. EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses

More information

A Brief Introduction to Matlab for Econometrics Simulations. Greg Fischer MIT February 2006

A Brief Introduction to Matlab for Econometrics Simulations. Greg Fischer MIT February 2006 A Brief Introduction to Matlab for Econometrics Simulations Greg Fischer MIT February 2006 Introduction First, Don t Panic! As the problem set assured you, the point of the programming exercises is to

More information

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System CHAPTER 1 INTRODUCTION Digital signal processing (DSP) technology has expanded at a rapid rate to include such diverse applications as CDs, DVDs, MP3 players, ipods, digital cameras, digital light processing

More information

LECTURE 1. What Is Matlab? Matlab Windows. Help

LECTURE 1. What Is Matlab? Matlab Windows. Help LECTURE 1 What Is Matlab? Matlab ("MATrix LABoratory") is a software package (and accompanying programming language) that simplifies many operations in numerical methods, matrix manipulation/linear algebra,

More information

Getting To Know Matlab

Getting To Know Matlab Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better

More information

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs). L A B 6 M A T L A B MATLAB INTRODUCTION Matlab is a commercial product that is used widely by students and faculty and researchers at UTEP. It provides a "high-level" programming environment for computing

More information

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013 Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB This note will introduce you to MATLAB for the purposes of this course. Most of the emphasis is on how to set up MATLAB on your computer. The purposes of this supplement are two.

More information

Teaching Manual Math 2131

Teaching Manual Math 2131 Math 2131 Linear Algebra Labs with MATLAB Math 2131 Linear algebra with Matlab Teaching Manual Math 2131 Contents Week 1 3 1 MATLAB Course Introduction 5 1.1 The MATLAB user interface...........................

More information

Lesson 6: Manipulating Equations

Lesson 6: Manipulating Equations Lesson 6: Manipulating Equations Manipulating equations is probably one of the most important skills to master in a high school physics course. Although it is based on familiar (and fairly simple) math

More information

Introduction to Unix - Lab Exercise 0

Introduction to Unix - Lab Exercise 0 Introduction to Unix - Lab Exercise 0 Along with this document you should also receive a printout entitled First Year Survival Guide which is a (very) basic introduction to Unix and your life in the CSE

More information

1.7 Limit of a Function

1.7 Limit of a Function 1.7 Limit of a Function We will discuss the following in this section: 1. Limit Notation 2. Finding a it numerically 3. Right and Left Hand Limits 4. Infinite Limits Consider the following graph Notation:

More information

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

More information

CME 193: Introduction to Scientific Python Lecture 1: Introduction

CME 193: Introduction to Scientific Python Lecture 1: Introduction CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements

More information

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed

More information

ENGR 1181 MATLAB 05: Input and Output

ENGR 1181 MATLAB 05: Input and Output ENGR 1181 MATLAB 05: Input and Output Learning Objectives 1. Create a basic program that can be used over and over or given to another person to use 2. Demonstrate proper use of the input command, which

More information

Entering data into memory with MATLAB

Entering data into memory with MATLAB Entering data into memory with MATLAB x=3 x = 3 A ; (semicolon) in matlab is the same thing as pressing inside a program; its use is necessary as when you execute a program you are not

More information

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3. MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4

More information

Lab 1: Setup 12:00 PM, Sep 10, 2017

Lab 1: Setup 12:00 PM, Sep 10, 2017 CS17 Integrated Introduction to Computer Science Hughes Lab 1: Setup 12:00 PM, Sep 10, 2017 Contents 1 Your friendly lab TAs 1 2 Pair programming 1 3 Welcome to lab 2 4 The file system 2 5 Intro to terminal

More information

Math 25 and Maple 3 + 4;

Math 25 and Maple 3 + 4; Math 25 and Maple This is a brief document describing how Maple can help you avoid some of the more tedious tasks involved in your Math 25 homework. It is by no means a comprehensive introduction to using

More information

To start using Matlab, you only need be concerned with the command window for now.

To start using Matlab, you only need be concerned with the command window for now. Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

More information

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu 0. What is MATLAB? 1 MATLAB stands for matrix laboratory and is one of the most popular software for numerical computation. MATLAB s basic

More information

Computer Vision. Matlab

Computer Vision. Matlab Computer Vision Matlab A good choice for vision program development because Easy to do very rapid prototyping Quick to learn, and good documentation A good library of image processing functions Excellent

More information

Depending on the computer you find yourself in front of, here s what you ll need to do to open SPSS.

Depending on the computer you find yourself in front of, here s what you ll need to do to open SPSS. 1 SPSS 11.5 for Windows Introductory Assignment Material covered: Opening an existing SPSS data file, creating new data files, generating frequency distributions and descriptive statistics, obtaining printouts

More information

Exercises: Instructions and Advice

Exercises: Instructions and Advice Instructions Exercises: Instructions and Advice The exercises in this course are primarily practical programming tasks that are designed to help the student master the intellectual content of the subjects

More information

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28)   First Name: Last Name: NetID: CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) http://www.cs.cornell.edu/courses/cs1110/2016sp/labs/lab01/lab01.pdf First Name: Last Name: NetID: Goals. Learning a computer language is a lot like learning

More information

ENCM 339 Fall 2017: Editing and Running Programs in the Lab

ENCM 339 Fall 2017: Editing and Running Programs in the Lab page 1 of 8 ENCM 339 Fall 2017: Editing and Running Programs in the Lab Steve Norman Department of Electrical & Computer Engineering University of Calgary September 2017 Introduction This document is a

More information

MITOCW ocw f99-lec07_300k

MITOCW ocw f99-lec07_300k MITOCW ocw-18.06-f99-lec07_300k OK, here's linear algebra lecture seven. I've been talking about vector spaces and specially the null space of a matrix and the column space of a matrix. What's in those

More information

University of Alberta

University of Alberta A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.

More information

APPM 2360 Project 2 Due Nov. 3 at 5:00 PM in D2L

APPM 2360 Project 2 Due Nov. 3 at 5:00 PM in D2L APPM 2360 Project 2 Due Nov. 3 at 5:00 PM in D2L 1 Introduction Digital images are stored as matrices of pixels. For color images, the matrix contains an ordered triple giving the RGB color values at each

More information

CSCI 1100L: Topics in Computing Lab Lab 1: Introduction to the Lab! Part I

CSCI 1100L: Topics in Computing Lab Lab 1: Introduction to the Lab! Part I CSCI 1100L: Topics in Computing Lab Lab 1: Introduction to the Lab! Part I Welcome to your CSCI-1100 Lab! In the fine tradition of the CSCI-1100 course, we ll start off the lab with the classic bad joke

More information

Arduino IDE Friday, 26 October 2018

Arduino IDE Friday, 26 October 2018 Arduino IDE Friday, 26 October 2018 12:38 PM Looking Under The Hood Of The Arduino IDE FIND THE ARDUINO IDE DOWNLOAD First, jump on the internet with your favorite browser, and navigate to www.arduino.cc.

More information

Part II Composition of Functions

Part II Composition of Functions Part II Composition of Functions The big idea in this part of the book is deceptively simple. It s that we can take the value returned by one function and use it as an argument to another function. By

More information

Introduction to Programming

Introduction to Programming CHAPTER 1 Introduction to Programming Begin at the beginning, and go on till you come to the end: then stop. This method of telling a story is as good today as it was when the King of Hearts prescribed

More information

The inverse of a matrix

The inverse of a matrix The inverse of a matrix A matrix that has an inverse is called invertible. A matrix that does not have an inverse is called singular. Most matrices don't have an inverse. The only kind of matrix that has

More information

Adding content to your Blackboard 9.1 class

Adding content to your Blackboard 9.1 class Adding content to your Blackboard 9.1 class There are quite a few options listed when you click the Build Content button in your class, but you ll probably only use a couple of them most of the time. Note

More information

Introduction to Programming with JES

Introduction to Programming with JES Introduction to Programming with JES Titus Winters & Josef Spjut October 6, 2005 1 Introduction First off, welcome to UCR, and congratulations on becoming a Computer Engineering major. Excellent choice.

More information

Drawing in 3D (viewing, projection, and the rest of the pipeline)

Drawing in 3D (viewing, projection, and the rest of the pipeline) Drawing in 3D (viewing, projection, and the rest of the pipeline) CS559 Spring 2017 Lecture 6 February 2, 2017 The first 4 Key Ideas 1. Work in convenient coordinate systems. Use transformations to get

More information

An Introduction to MATLAB

An Introduction to MATLAB An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High level language Programing language and development environment Built-in development tools Numerical manipulation Plotting of

More information

It s possible to get your inbox to zero and keep it there, even if you get hundreds of s a day.

It s possible to get your  inbox to zero and keep it there, even if you get hundreds of  s a day. It s possible to get your email inbox to zero and keep it there, even if you get hundreds of emails a day. It s not super complicated, though it does take effort and discipline. Many people simply need

More information

XP: Backup Your Important Files for Safety

XP: Backup Your Important Files for Safety XP: Backup Your Important Files for Safety X 380 / 1 Protect Your Personal Files Against Accidental Loss with XP s Backup Wizard Your computer contains a great many important files, but when it comes to

More information

the star lab introduction to R Day 2 Open R and RWinEdt should follow: we ll need that today.

the star lab introduction to R Day 2 Open R and RWinEdt should follow: we ll need that today. R-WinEdt Open R and RWinEdt should follow: we ll need that today. Cleaning the memory At any one time, R is storing objects in its memory. The fact that everything is an object in R is generally a good

More information

An Introductory Tutorial: Learning R for Quantitative Thinking in the Life Sciences. Scott C Merrill. September 5 th, 2012

An Introductory Tutorial: Learning R for Quantitative Thinking in the Life Sciences. Scott C Merrill. September 5 th, 2012 An Introductory Tutorial: Learning R for Quantitative Thinking in the Life Sciences Scott C Merrill September 5 th, 2012 Chapter 2 Additional help tools Last week you asked about getting help on packages.

More information

CMSC/BIOL 361: Emergence Cellular Automata: Introduction to NetLogo

CMSC/BIOL 361: Emergence Cellular Automata: Introduction to NetLogo Disclaimer: To get you oriented to the NetLogo platform, I ve put together an in-depth step-by-step walkthrough of a NetLogo simulation and the development environment in which it is presented. For those

More information

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller Table of Contents Introduction!... 1 Part 1: Entering Data!... 2 1.a: Typing!... 2 1.b: Editing

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

Homework #2: Introduction to Images Due 4 th Week of Spring 2018 at the start of lab CSE 7, Spring 2018

Homework #2: Introduction to Images Due 4 th Week of Spring 2018 at the start of lab CSE 7, Spring 2018 Homework #2: Introduction to Images Due 4 th Week of Spring 2018 at the start of lab CSE 7, Spring 2018 Before beginning this homework, create a new Notepad++ file in your cs7sxx home directory on ieng6

More information

A Guide to Condor. Joe Antognini. October 25, Condor is on Our Network What is an Our Network?

A Guide to Condor. Joe Antognini. October 25, Condor is on Our Network What is an Our Network? A Guide to Condor Joe Antognini October 25, 2013 1 Condor is on Our Network What is an Our Network? The computers in the OSU astronomy department are all networked together. In fact, they re networked

More information

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay.

Welcome Back! Without further delay, let s get started! First Things First. If you haven t done it already, download Turbo Lister from ebay. Welcome Back! Now that we ve covered the basics on how to use templates and how to customise them, it s time to learn some more advanced techniques that will help you create outstanding ebay listings!

More information

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet. Mr G s Java Jive #2: Yo! Our First Program With this handout you ll write your first program, which we ll call Yo. Programs, Classes, and Objects, Oh My! People regularly refer to Java as a language that

More information

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below.

The first thing we ll need is some numbers. I m going to use the set of times and drug concentration levels in a patient s bloodstream given below. Graphing in Excel featuring Excel 2007 1 A spreadsheet can be a powerful tool for analyzing and graphing data, but it works completely differently from the graphing calculator that you re used to. If you

More information

CS354 gdb Tutorial Written by Chris Feilbach

CS354 gdb Tutorial Written by Chris Feilbach CS354 gdb Tutorial Written by Chris Feilbach Purpose This tutorial aims to show you the basics of using gdb to debug C programs. gdb is the GNU debugger, and is provided on systems that

More information

Using the Zoo Workstations

Using the Zoo Workstations Using the Zoo Workstations Version 1.86: January 16, 2014 If you ve used Linux before, you can probably skip many of these instructions, but skim just in case. Please direct corrections and suggestions

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Writing to and reading from files

Writing to and reading from files Writing to and reading from files printf() and scanf() are actually short-hand versions of more comprehensive functions, fprintf() and fscanf(). The difference is that fprintf() includes a file pointer

More information

Flow Control and Functions

Flow Control and Functions Flow Control and Functions Script files If's and For's Basics of writing functions Checking input arguments Variable input arguments Output arguments Documenting functions Profiling and Debugging Introduction

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab What is Matlab The software program called Matlab (short for MATrix LABoratory) is arguably the world standard for engineering- mainly because of its ability to do very quick prototyping.

More information

Binary, Hexadecimal and Octal number system

Binary, Hexadecimal and Octal number system Binary, Hexadecimal and Octal number system Binary, hexadecimal, and octal refer to different number systems. The one that we typically use is called decimal. These number systems refer to the number of

More information

6.001 Notes: Section 15.1

6.001 Notes: Section 15.1 6.001 Notes: Section 15.1 Slide 15.1.1 Our goal over the next few lectures is to build an interpreter, which in a very basic sense is the ultimate in programming, since doing so will allow us to define

More information

Intro. Scheme Basics. scm> 5 5. scm>

Intro. Scheme Basics. scm> 5 5. scm> Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

More information

Welcome to Introduction to Microsoft Excel 2010

Welcome to Introduction to Microsoft Excel 2010 Welcome to Introduction to Microsoft Excel 2010 2 Introduction to Excel 2010 What is Microsoft Office Excel 2010? Microsoft Office Excel is a powerful and easy-to-use spreadsheet application. If you are

More information

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming

More information

How do I use BatchProcess

How do I use BatchProcess home news tutorial what can bp do purchase contact us TUTORIAL Written by Luke Malpass Sunday, 04 April 2010 20:20 How do I use BatchProcess Begin by downloading the required version (either 32bit or 64bit)

More information

If Statements, For Loops, Functions

If Statements, For Loops, Functions Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements

More information

These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

More information

An Introduction to MATLAB See Chapter 1 of Gilat

An Introduction to MATLAB See Chapter 1 of Gilat 1 An Introduction to MATLAB See Chapter 1 of Gilat Kipp Martin University of Chicago Booth School of Business January 25, 2012 Outline The MATLAB IDE MATLAB is an acronym for Matrix Laboratory. It was

More information