MATLAB

advertisement
Methodologies for Population/Quantitative Genetics
Animal Science 562
MATLAB
“MATLAB can be used as an interactive programmable
calculator that can handle vectors and matrices, or as a
programming language.”
F. Kunert (ISU Dept. of Mathematics)
TUTORIAL
To get started:
http://www.math.iastate.edu/mathdoc/matlab.html
Access
•
Logon to a Vincent work station
•
Telnet to isua
•
Issue the following commands
¾ add matlab
¾ matlab
•
Basic MATLAB commands
o Initializing vectors and matrices
o Commands to do something
o Execution one-line-at-a-time
o Execution of a whole set of commands
Usage notes
•
Enter commands following the >> symbol
•
A command line ends with a semicolon (;)
•
Names of matrices are written as single uppercase letters
•
Vectors are written as single lowercase letters
•
MATLAB is case-sensitive in the names of commands, functions, and variables, e.g.,
solve UT is not the same as solve ut.
•
Any text following an exclamation point is a comment
1
MATLAB
AnS 562
m-files
MATLAB can execute a sequence of statements stored as a file.
A script file consists of a sequence of normal MATLAB statements. If the file has e.g., the
filename rotate.m, then the MATLAB command rotate will cause the statements in the file to be
executed.
The filename extension “.m” is required for MATLAB to recognize and execute the file as a
MATLAB program.
The exercise
You’ll need to use a computer with both X-Windows and Microsoft Internet Explorer. Log onto
your Vincent account through X-Windows, and open Internet Explorer to:
http://www.anslab.iastate.edu/Class/AnS562/Notes/Programs.html
The four links open two data files and two MATLAB program files. Click on the first link
(“One-way program”), type <CTL-A> (this selects all text), then <CTL-C> (this copies the
selected text).
Click into your X-Windows screen and type “emacs” at the prompt. This should start the emacs
editing program. Select the Edit menu, then select Paste. This will paste the text copied from
the Website into the emacs editor. Select the File menu, and click “Save buffer As”, then go to
the bottom of the window and type the name of the file. In this case, this MATLAB program file
should be named “pgm1.m”.
Select “Clear” from the Edit menu. This clears the text from the emacs screen. Return to
Internet Explorer, click on the “Back” button to return to the main Web menu, and select the next
file to be copied (“One-way data”) and repeat the copy/paste/save steps until all four files are
copied and saved.
“One-way program” should be named “program1.m”; “One-way data” should be named “data”;
“Two-way program” should be names “program2.m”; and “Two-way data” is the same as the
data for the one-way program. Now you’re ready to start MATLAB and run the programs.
2
Download