Using MATLAB: A Primer and Data Input, Study notes of Experimental Physics

An introduction to using matlab, a popular programming language for numerical computing. It covers opening matlab, making simple calculations, creating arrays, and inputting data from files. The document also includes examples of matlab code for creating plots and provides useful information on the colon operator and selecting rows and columns of arrays.

Typology: Study notes

Pre 2010

Uploaded on 08/09/2009

koofers-user-qyt-1
koofers-user-qyt-1 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Using MATLAB
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);
pf3

Partial preview of the text

Download Using MATLAB: A Primer and Data Input and more Study notes Experimental Physics in PDF only on Docsity!

Using MATLAB

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.