

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!


A primer on MATLAB is given in Napolitano, Appendix D, pp 419 ff Running it ๏ When you open it, it defaults to three windows: Command, current directory/workspace, history ๏ Simple calculations can be made in the command window step by step ๏ Long or repeated calculations should be done with a program (.m) file (start one by clicking File..New..M File) Inputting data: ๏ x=[0:1:20] creates an array [0 1 2 3 ... 20] (start at 0, increment in steps of one, until you get to 20) ๏ x=[1 3 5 3 8] creates an array with the values given ๏ load c:\mydata\mine.txt loads space or tab delimited columns of ascii numbers into an array of that name. A matlab 6.5 variant is B=load('mine.dat'), which names the vector array (make sure you include the correct path to the data) ๏ A different approach is to read the data from a file in a specific format fid=fopen('sc1.lis'); a=fscanf(fid,'%f')'; fclose(fid);
Useful points ๏ The colon operator uses the following rules to create regularly spaced vectors: j:kis the same as [j,j+1,...,k] ๏ Below are the definitions that govern the use of the colon to pick out selected rows, columns, and elements of vectors, matrices, and higher-dimensional arrays: A(:,j)is the j-th column of A B=A(:,1) creates a one-d array B that has the first column of A in it. A(i,:)is the i-th row of A A(i,j,k,:)is a vector in four-dimensional array A.