Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 2 SEG7550 Introduction to MATLAB II

Similar presentations


Presentation on theme: "Tutorial 2 SEG7550 Introduction to MATLAB II"— Presentation transcript:

1 Tutorial 2 SEG7550 Introduction to MATLAB II
25th, Sep., 2009

2 Outline Source of financial data Generate graphs in MATLAB
Review programs in class

3

4

5 Histogram plot n = hist(Y) bins the elements in vector Y into 10 equally spaced containers and returns the number of elements in each container as a row vector. n = hist(Y,x) where x is a vector, returns the distribution of Y among length(x) bins with centers specified by x. For example, if x is a 5-element vector, hist distributes the elements of Y into five bins centered on the x-axis at the elements in x, none of which can be complex.

6 Histogram plot Example: x = -4:0.1:4; y = randn(10000,1); hist(y,x)

7 Plot (basic) plot(X,Y) plots vector Y versus vector X.
plot(Y) plots the columns of Y versus their index Title: use function ‘title()’ X,Y axis labels: use function ‘xlabel()’ and ‘ylabel() ’

8 Plot multiple data sets in one graph
Example: X=0:0.1:10; Y1=X.^2-10.*X+15; Y2=-X.^2+10.*X; Y3=0.5.*(X.^2); plot(X,Y1,X,Y1,X,Y3) title(‘graph’) xlabel(‘x’) ylabel(‘y’)

9 Plot multiple data sets in sub graphs
subplot Create axes in tiled positions. H = subplot(m,n,p), or subplot(mnp), breaks the figure window into an m-by-n matrix of small axes, selects the p-th axes for for the current plot, and returns the axis handle. The axes are counted along the top row of the Figure window, then the second row, etc. For example, subplot(2,1,1), plot(X,Y1) subplot(2,1,2), plot(X,Y2)

10 Plot multiple data sets in sub graphs
subplot('position',[left bottom width height]) creates an axis at the specified position in normalized coordinates (in in the range from 0.0 to 1.0). For example subplot(2,2,[1 3]) plot(X,Y3) subplot(2,2,2) plot(X,Y1) subplot(2,2,4) plot(X,Y2)

11 Plot multiple data sets in sub graphs
Or subplot(2,2,1:2) plot(X,Y3) subplot(2,2,3) plot(X,Y1) subplot(2,2,4) plot(X,Y2)

12 Distinguish two plots

13 Distinguish two plots For example: plot(X,Y1,’r-.’,X,Y2,’bo’)

14 Legend legend(string1,string2,string3 ., ...) puts a legend on the current plot using the specified strings as labels legend(H,string1,string2,string3, ...) puts a legend on the plot containing the handles in the vector H using the specified strings as labels for the corresponding handles. legend(AX,...) puts a legend on the axes with handle AX. legend(M), where M is a string matrix, and LEGEND(H,M) where H is a vector of handles to lines and patches also works. legend('off') removes the legend from the current axes.

15 Legend legend() with no arguments refreshes the current legend, if there is one. If there are multiple legends present, legend(legendhandle) refreshes the specified legend. legend(...,Pos) places the legend in the specified location: 0 = Automatic "best" placement (least conflict with data) 1 = Upper right-hand corner (default) 2 = Upper left-hand corner 3 = Lower left-hand corner 4 = Lower right-hand corner -1 = To the right of the plot

16 Legend To move the legend, press the left mouse button on the legend and drag to the desired location. Legend() works on line graphs, bar graphs, pie graphs, ribbon plots, etc. You can label any solid-colored patch or surface object. Double clicking on a label allows you to edit the label.

17 Text plot(0:pi/20:2*pi,sin(0:pi/20:2*pi))
text(X,Y,'string') adds the text in the quotes to location (X,Y) on the current axes, where (X,Y) is in units from the current plot. If X and Y are vectors, TEXT writes the text at all locations given. If 'string' is an array the same number of rows as the length of X and Y, TEXT marks each point with the corresponding row of the 'string' array. Example plot(0:pi/20:2*pi,sin(0:pi/20:2*pi)) text(pi,0,' \leftarrow sin(\pi)','FontSize',18)

18 Print Print Figure or model. Save to disk as image or M-file.
print: it sends the current figure to your current printer. The size and shape of the printed output depends on the Figure's PaperPosition[mode] properties and your default print command as specified in your PRINTOPT.M file. print filename: it directs the output to the PostScript file designated by filename. If filename does not include an extension, print appends an appropriate extension. print -dformat filename: it exports the figure to the specified file using the specified graphics format, (such as bmp eps and jpeg).

19 Review programs in class
The models:

20 Review programs in class
The models:

21 Review programs in class
Some functions round: Round to nearest integer diff: Differences and approximate derivatives diff(x) calculates differences between adjacent elements of X. Load: load filename loads all the variables from the file specified by filename.

22 System Identification Toolbox
Estimate linear and nonlinear mathematical models of dynamic systems from measured data. Simulate output of a system for given input Predict future outputs on previous observations of inputs and outputs

23 Manuals for System Identification Toolbox
Getting started User guide

24 Review programs in class
Some functions idinput: idinput generates input signals of different kinds, which are typically used for identification purposes. u is returned as a matrix or column vector. u = idinput(400, 'rbs', [0 0.3]); 400 is # of data generated. rbs means these random data are from gaussian distribution [0,0.03] is the lower and upper bound. poly2th:Constructs a "theta-matrix" from given polynomials. th0 = poly2th(A, B, C); th0 contains parameters of the equation: A(q) y(t) = B(q) u(t-1) + [C(q)] e(t)

25 idsim: Simulate systems specified in theta format
Some functions idsim: Simulate systems specified in theta format y = idsim([u e], th0); u is data, e is noise, and th0 is the parameter. idplot: Plot input-output data. th2ff: Compute the frequency response and standard deviations of a theta format model. ffplot: Plot frequency response and spectra

26 Review programs in class
Some functions: armax: Estimate the parameters of an ARMAX or ARMA model. m = armax(data,orders) returns an idpoly model m with estimated parameters and covariances (parameter uncertainties). Estimates the parameters using the prediction-error method and specified orders. th1 = armax([y u], [ ]); [y,u] is data. [ ]is order. The first three is the order of parameters and the last one is for lag (or delay) bodeplot: Plot Bode frequency response and return plot handle. A Bode plot is a graph of the logarithm of the transfer function of a linear, time-invariant system versus frequency, plotted with a log-frequency axis, to show the system's frequency response.

27 Useful materials for matlab
Econometrics Toolbox: by James P. LeSage UCSD GARCH


Download ppt "Tutorial 2 SEG7550 Introduction to MATLAB II"

Similar presentations


Ads by Google