{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

MATLABguide

# MATLABguide - MATLAB GUIDE UMD PHYS375 FALL 2010...

This preview shows pages 1–4. Sign up to view the full content.

MATLAB GUIDE UMD PHYS375 FALL 2010 DIRECTORIES Find the current directory you are in: >> pwd ans = C:\Documents and Settings\ian\My Documents\MATLAB [Note that Matlab assigned this string of characters to a variable name “ ans ”. It does this every time it is asked to produce something without being told where to assign the value. For instance, >> 1+1 ans = 2 ] You can also assign the value to a variable of your choice: >> a=pwd a = C:\Documents and Settings\ian\My Documents\MATLAB Matlab will echo the explicit command unless you end your statement with a semicolon: >> a=pwd; All the usual MSDOS directory manipulation applies: >> cd ../../Desktop >> dir . CLASSES PROPOSALS .. PRESENTATION PROJECTS Note that Matlab is case-sensitive, and all built-in commands we will be using are lowercase. Change directories to C:\Users\p375-0X\Documents\MATLAB (“X” varies at each lab station) and make a subdirectory with your last name. You will be using this directory all semester. It is also recommended that you back up this data on a USB thumb drive.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
MATRICES AND ARRAYS From the Matlab “Getting Started” Guide ( http://www.mathworks.com/access/helpdesk/help/pdf_doc/matlab/getstart.pdf ): “In the MATLAB environment, a matrix is a rectangular array of numbers. Special meaning is sometimes attached to 1-by-1 matrices, which are scalars, and to matrices with only one row or column, which are vectors. MATLAB has other ways of storing both numeric and nonnumeric data, but in the beginning, it is usually best to think of everything as a matrix. The operations in MATLAB are designed to be as natural as possible. Where other programming languages work with numbers one at a time, MATLAB allows you to work with entire matrices quickly and easily.” You can create an array of data with square brackets: >> a=[3 5 9 6] a = 3 5 9 6 Here, it is a row vector. You can create a column vector as well: >> a=[3; 5; 9; 6] a = 3 5 9 6 Or just use the transpose operator on a row vector: >> a=[3 5 9 6]' a = 3 5 9 6 Note that it is sometimes useful to add comments to your commands. You can do this with “ % ”: >> a=[3 5 9 6] %here is my comment a = 3 5 9 6 At any time you can see the variables in the workspace and their properties including dimensions etc: >> whos Name Size Bytes Class Attributes a 1x4 32 double You can save this array to a delimited text file named e.g. “data.dat” >> save -ascii data.dat a You can load data from a space/tab/etc delimited file of numbers:
>> load data.dat This creates an array named the same as the file, without the extension: >> whos Name Size Bytes Class Attributes a 1x4 32 double data 1x4 32 double You can also get information about a specific variable: >> length(a) ans = 4 You can concatenate these elements to other arrays: >> data=[[1 5 3 8]' data'] data = 1 3 5 5 3 9 8 6 Note that these are all logical statements, not algebraic. They can therefore be self- referential.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

MATLABguide - MATLAB GUIDE UMD PHYS375 FALL 2010...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online