Mat Class All | Matrix (Mathematics) | Matlab

of 50

Please download to get full document.

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
PDF
50 pages
0 downs
3 views
Share
Description
General Introduction These notes are mainly designed to help people begin display programming with the psychtoolbox. Although these notes also teach introductory programming, I’d also recommend the book: Basics of Matlab and Beyond, by Andrew Knight, published by Chapman and Hall/CRC In the Knight book Chpaters 1-11, 28-31 are probably the most crucial. Beginning programmers should work their way from the beginning. Programmers who are comfortable with another programming language should skim ov
Tags
Transcript
  General Introduction These notes are mainly designed to help people begin display programming withthe psychtoolbox. Although these notes also teach introductory programming, I’dalso recommend the book: Basics of Matlab and Beyond, by Andrew Knight, published by Chapman and Hall/CRC  In the Knight book Chpaters 1-11, 28-31 are probably the most crucial.Beginning programmers should work their way from the beginning. Programmerswho are comfortable with another programming language should skim over thefirst chapters and begin at Chapter 9.Comments/suggests very welcome –fine@salk.eduIone FineDept. of Psychology, UCSD9500 Gilman DriveLa Jolla, CA 92093-0109Topic 1 – What is programming?..........................................................................2Topic 2– Starting Matlab.......................................................................................4Topic 3 – Your first program.................................................................................6Program 1 – MixStrings.m.................................................................................6EXERCISE 1.................................................................................................8Topic 4 – Calculations...........................................................................................9EXERCISE 2...............................................................................................10Program 2 - Calculations.m.............................................................................10EXERCISE 3...............................................................................................11Topic 5 –Graphics I.............................................................................................12Program 3 – Squares.m..................................................................................12EXERCISE 4...............................................................................................13Topic 6 – Functions.............................................................................................14EXERCISE 5...............................................................................................15Topic 7 – Reading/Writing Data to files...............................................................16EXERCISE 6...............................................................................................17Topic 8 – Planning a program.............................................................................18Topic 9 – Starting Matlab (revisited)...................................................................20Topic 10 – Vectors, Matrices, Calculations, Operators.......................................23Program 4 (again) - Calculations.m.................................................................27EXERCISE 7...............................................................................................27Program 6 – CosmoSexQuiz.m.......................................................................28EXERCISE 8...............................................................................................29  Program 3 (again) – Squares.m......................................................................30EXERCISE 9...............................................................................................33Topic 13 –More Reading/Writing Data to files.....................................................33EXERCISE 6 (again)...................................................................................35Topic 14 – The PsychToolbox............................................................................36Topic 15 – Graphics, the good stuff....................................................................38Program 7 – Tiling.m...................................................................................38Topic 16 Visual Angle.........................................................................................41Program 8 – VisAng.m....................................................................................41Topic 17 Sinusoids and Gaussians.....................................................................43Program 9 – MakeGrating.m...........................................................................43Program 10 – GaussianWindow.m..................................................................45Program 11 – Shuffle.m..................................................................................46Topic 18 Calibration............................................................................................47Program 12 – Calibrate.m...............................................................................47Program 13 – GammaFit.m.............................................................................49Program 14 – BestGamma.m..........................................................................49Program 15 – LtoP.m......................................................................................50 Topic 1 – What is programming? (what is hardware, what is software, what is a computer language)  Programming is telling a computer what to do. There are only 2 tricky things 1) Computers are very stupid – you have to tell them exactly what to do 2) Computers don’t speak English. Any programming language is a compromisebetween the computer’s native language (0010001) and your native language(English). High level languages are closer to English, low level languages arecloser to computer-ese. The closer a language is to English, the easier it tends tobe to program, but the slower it is for the computer to interpret it. Low levellanguages tend to be hard to program but very fast to run. Matlab is a mid- tohigh level language. Like any language, programming languages have grammar. Like real languagessome things are easier to say in one language rather than another (Italian is thelanguage of love etc. etc.). Some languages are better for computations, othersfor graphics. Unlike people who speak real languages (with the exception of theFrench) computers are very fussy about grammatical errors. Like learning a reallanguage at first it will be hard to say the simplest thing, but it will get easier, fast.  Hardware  Hardware is the physical presence of the computer. The monitor. the hard drive,the CPU (central processing unit). Hardware is anything you can damage bypoking it with a screwdriver.  Software software = programs . Programs are instructions to your computer to behave in aparticular way. So a software program like Microsoft Office gets all machines tobehave in a particular way – the instructions are slightly different for differentcomputers (different hardware), but the program makes all computers behave(almost) the same.    All software is written in a programming language. Some programs, (like matlab)are there to help you write new programs. Matlab will run on Macs, PC, andUNIX. But some of the commands only run on some computers.  NOTE  – these days it is almost impossible to damage your computer by writing aprogram. The computer usually makes it very hard for you to do anything that willdamage it. In this class you won’t be using any commands that can do anypermanent damage. So crash your computer hard. Have fun!    Topic 2– Starting Matlab (starting Matlab, ,strings, indexing strings, who, using the command window)  If you need to, install Matlab. A month trial version is available fromhttp://www.mathworks.com/web_downloads/ Double click the Matlab icon. A window will come up. This is your “commandwindow”. You can type the computer commands here. The computer will alsosend you messages back here, usually messages telling you about problems. The Matlab command window has a prompt. If I want you to type something inthe command window I’ll start it with the prompt (you don’t type the prompt, it’salready there). Type at the prompt (>) >str=’this is my first program’; What you have done is told the computer to create a list of letters ‘this is my firstprogram’ and name that list of letters “str”. Str is a variable - The single quotestell the computer that it is a list of letters (not numbers, more on that later). A listof letters is called a string. >who Your computer will give you a list of all the variables you have. At the moment allyou have is str. >str Your computer tells you what is contained within str – it’s a list of letters.Compare these two commands (look carefully, there is a difference.) >str=’hello there’;>str=’hello there’ The semi-colon tells the computer whether or not you want it to display the outputof each command. >who str is still there >str But the list of letters contained within str has changed >str(3) You’ve asked the computer to display the third letter in str. What is the third letter in ‘hello there’? mixstr=str;
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks