MATLAB Controlling Plot Function Description Plotx 1 y
MATLAB – Controlling Plot Function Description Plot(x 1, y 1, s 1, x 2, y 2, s 2, … ) Combines the plots defined by the (x, y, s) triples loglog(x 1, y 1, s 1, x 2, y 2, s 2, … ) loglog(…) is the same as plot(…) except a logarithmic (base 10) scale is used for the X-axis and the Y-axis semilogx(x 1, y 1, s 1, x 2, y 2, s 2, …) semilogx(…) is the same as plot(…) except a logarithmic (base 10) scale is used for the X-axis semilogy(x 1, y 1, s 1, x 2, y 2, s 2, …) semilogy(…) is the same as plot(…) except a logarithmic (base 10) scale is used for the Y-axis plotyy(x 1, y 1, x 2, y 2) Plots Y 1 versus X 1 with y-axis labeling on the left and plots Y 2 versus X 2 with y-axis labeling on the right Chapter 5 Uiduk University
MATLAB – Controlling Plot EX 1) >> t=0: 0. 1: 100; >> x=1 + 0. 5*exp(-0. 05*t). * sin(t + pi/2); >> plot(t, x); >> grid on EX 2) >> loglog(t, x); >> axis([0, 100, 0. 1, 10]); >> grid on Chapter 5 Uiduk University
MATLAB – Controlling Plot EX 3) >> t=0: 0. 1: 100; >> x=1 + 0. 5*exp(-0. 05*t). * sin(t + pi/2); >> semilogx(t, x); >> grid on EX 4) >> semilogy(t, x); >> axis([0, 100, 0. 1, 10]); >> grid on Chapter 5 Uiduk University
MATLAB – Controlling Plot EX 5) >> x = 0: 0. 1: 10; >> y 1 = x. ^2 + 1; >> y 2 = 400 * sin(sqrt(x)). / exp(x); >> plot(x, y 1, x, y 2); EX 6) >> x = 0: 0. 1: 10; >> y 1 = x. ^2 + 1; >> y 2 = 400 * sin(sqrt(x)). / exp(x); >> plotyy(x, y 1, x, y 2); Chapter 5 Uiduk University
MATLAB – Adding Plot Function Description hold on Holds the current plot and all axis properties so that subsequent graphic commands add to the existing graph hold off Returns to the default mode EX 7) x = 0: 0. 1: 10; >> y 1 = cos(x); >> y 2 = cos(x - pi / 6); >> y 3 = exp(-0. 5*x). * sin(x); >> plot(x, y 1); >> hold on >> plot(x, y 2); >> hold off >> hold on >> plot(x, y 3); >> hold off >> grid Chapter 5 Uiduk University
MATLAB – Graph Adjustment Function Description axis(v) Sets scaling for the x- and y-axis on the current plot set(gca, axis_name, v) Chapter 5 Sets the tick mark of the axis with vector v axis_name: ‘xtick’ – the tick mark of the x-axis ‘ytick’ – the tick mark of the y – axis v : vector legend(s 1, s 2, … ) Puts a legend on the current plot using the specified strings as labels text(x, y, s) Adds the text s to location (x, y) on the current axis gtext(s) Place text s with mouse Uiduk University
MATLAB – Axis Adjustment EX 8) x = 0: 0. 1: 10; >> y 1 = cos(x); >> y 2 = cos(x - pi / 6); >> y 3 = exp(-0. 5*x). * sin(x); >> plot(x, y 1, x, y 2, x, y 3); >> grid on >> xt = [0, 2, 4, 6, 8, 10]; >> yt = [-1, -0. 5, 0, 0. 5, 1]; >> set(gca, 'xtick', xt); >> set(gca, 'ytick', yt); Chapter 5 Uiduk University
MATLAB – Legend & Axis Scale EX 9) >> x = 0: 0. 1: 10; >> y 1 = cos(x); >> y 2 = cos(x - pi / 6); >> y 3 = exp(-0. 5*x). * sin(x); >> plot(x, y 1, x, y 2, x, y 3); >> grid on >> legend('cos(x)', 'cos(x - 30)', 'e(-0. 5 x) sin(x)'); >> v = [0, 6, -0. 5, 0. 5]; >> axis(v); Chapter 5 Uiduk University
MATLAB – Adding Text EX 10) >> x = 0: 0. 1: 10; >> y 1 = cos(x); >> y 2 = cos(x - pi / 6); >> y 3 = exp(-0. 5*x). * sin(x); >> plot(x, y 1, x, y 2, x, y 3); >> v = [0, 6, -0. 5, 0. 5]; >> axis(v); >> grid on >> legend('cos(x)', 'cos(x - 30)', 'e(-0. 5 x) sin(x)'); >> text(4. 6, -0. 1, 'Cross Point'); Chapter 5 Uiduk University
MATLAB – Polar Coordinate Plot Chapter 5 Function Description polar(theta, r, s) Makes a plot using polar coordinates of the angle ‘theta’, in radians, versus the radius ‘r’ [theta, r] = cart 2 pol(x, y) Transforms the corresponding elements of data stored in Cartesian coordinates x, y to polar coordinates angle ‘theta’, radius ‘r’ [x, y] = pol 2 cart(theta, r) Transforms the corresponding elements of data stored in polar coordinates ‘theta’, radius ‘r’ to Cartesian coordinates x, y Uiduk University
MATLAB – Adding Text EX 11) >> theta = 0: (2*pi)/100: 2*pi; >> r = (sin(theta) + theta) / (2*pi); >> polar(theta, r); Chapter 5 Uiduk University
- Slides: 12