180 likes | 534 Views
제어공학기초 설계실습 #4. Plotting and Graphics. 실험실습 #4 안내서. 실험실습 번호 : #4 실험실습 일시 : 2007. . . 담당교수 : 담당조교 : , . 제목 : Plotting and Graphics 목적 : Matlab 에서의 결과 그림을 도시하는 각종 방법에 대해 익힘 실습에 필요한 기초지식 : 슬라이드 유인물 참조 실습절차 : 슬라이드 유인물 참조.
E N D
제어공학기초 설계실습 #4 Plotting and Graphics
실험실습 #4 안내서 • 실험실습 번호 : #4 • 실험실습 일시: 2007. . . • 담당교수 : • 담당조교 : , 제목 : Plotting and Graphics 목적 : Matlab에서의 결과 그림을 도시하는 각종 방법에 대해 익힘 실습에 필요한 기초지식 : 슬라이드 유인물 참조 실습절차 : 슬라이드 유인물 참조
Plotting & Graphics: Basic 2-D Graphics • plot(y) • plot(rand(1, 20)) • plot(x, y) • x = 0 : pi/40 : 4*pi; • plot(x, sin(x)) • plot([0 4], [1 3]) • ezplot(‘tan(x)’)
Plotting & Graphics: Labels • title, xlabel, ylabel • gtext, text • grid >> plot([1 1 2 3 3], [0 2 3 2 0]) >> title(‘House') >> xlabel('horizontal') >> ylabel('vetical') >> gtext('window') >> text(2,1,'door') >> grid
hold (on)/ hold (off): toggle plot(x1, y1, x2, y2, x3, y3, …) plotyy(x, sin(x), x, 10*cos(x)) independent y-axis labels on the left and the right plot(x, y) x and y may both be matrices Multiple Plots on the Same Axes
Line Styles, Markers and Colors • Line styles • plot(x, y, ‘--’) • -(solid), --(dashed), :(dotted), -.(dashdot) • markers • plot(x, y, ‘o’) • .(point), o(circle), x, *, +, s(quare), d(iamond),v(triangle down), ^(triangle up), <(triangle left), >(triangle right) • colors • plot(x, y, ‘r’) • c(yan), m(agenta), y(ellow), r(ed), g(reen), b(lue), (blac)k, w(hite) • ex: plot(x, sin(x), ‘b.-v’, x, cos(x), ‘om--’)
Axis Limits • axis( [xmin, xmax, ymin, ymax] ) • inf, -inf: autoscaled limit • axis auto • v = axis: current axis scaling in the vector v • axis manual: hold 동작시 작용 • axis equal / axis normal • axis off / axis on • axes: particular graphics object • includes x-axis, y-axis, tick marks, labels, the actual graphs, text included in the figure
Multiple Plots in a Figure • subplot(m, n, p) • m x n small sets of axes • p-th set for the current plot • figure(h) • create a new figure window • or makes figure h the current figure • h: the handle of the figure • clf • clears the current figure windows • cla • deletes all plots and text from the current axes
예제: Multiple plots in a figure % Multiple plots in a figure % [x, y] = meshgrid(-3:0.3:3); z = x.* exp(-x.^2 - y.^2); subplot(2, 2, 1) mesh(z), title('subplot(2,2,1)') subplot(2, 2, 2) mesh(z) view(-37.5, 70), title('subplot(2,2,2)') subplot(2, 2, 3) mesh(z) view(37.5, -10), title('subplot(2,2,3)') subplot(2, 2, 4) mesh(z) view(0,0), title('subplot(2,2,4)')
Graphical Input • Graphical input • [x, y] = ginput • select an unlimited number of points from the current graph using a mouse or arrow keys • [x, y] = ginput(n) • must select exactly n points • Logarithmic plots • semilogx(x, y) • plots x with a log10 scale and y with a linear scale • semilogy(x, y) • plots x with a linear scale and y with a log10 scale • loglog(x, y) • plots x and y with a log10 scale
Logarithmic Plots % Logarithmic plots % x = 0:0.01:4; y = exp(x); subplot(2,2,1) plot(x, y), grid subplot(2,2,2) semilogx(x, y), grid subplot(2,2,3) semilogy(x, y), grid subplot(2,2,4) loglog(x, y), grid
3-D Plots • plot3 • plot3(x, y, z) • Animated 3-D plots with comet3 • comet3(x, y, z) • it draws with a moving ‘comet head’ • Mesh surfaces • [x y] = meshgrid(0:5) x = 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 0 1 2 3 4 5 y = 0 0 0 0 0 0 1 1 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 5 5 5 5 5 5
예제: plot3 % plot3 % plot3(rand(1,10), rand(1,10), rand(1,10)) % plot3 % t = 0:pi/50:10*pi; plot3(exp(-0.02*t).*sin(t),… exp(-0.02*t).*cos(t), t),… xlabel('x-axis'), ylabel('y-axis'),… zlabel('z-axis')
예제: Mesh surfaces % Mesh surfaces % [x y] = meshgrid(-8:0.5:8); r = sqrt(x.^2 + y.^2) + eps; z = sin(r) ./ r; mesh(z) % Mesh surfaces % [x y] = meshgrid(-8:0.5:8); r = sqrt(x.^2 + y.^2) + eps; z = sin(r) ./ r; surf(z)
Rotation of 3-D Graphs • view(az, el) • az(azimuth) • viewpoint about the z-axis • in degree • default value: -37.5o • el(elevation) • the angle a line from the viewpoint makes with the x-y plane • in degree • default value: 30o • pause(n) • suspends execution for n seconds % Rotation of 3-D graphs % a = zeros(30, 30); a(:, 15) = 0.2 * ones(30, 1); a(7, :) = 0.1 * ones(1, 30); a(15, 15) = 1; el = 30; for az = -37.5:15:-37.5+360 mesh(a), view(az, el) pause(0.5) end
요약: Plotting and Graphics • Plotting and Graphics Basic commands: plot, loglog, semilogx, semilogy, polar
요약: Plotting and Graphics Some techniques
1) 앞에 설명된 MATLAB example 들을 실행해 보시오. 2) 다음 문제에 대해 그림을 그리시오. Mercury's Orbit about Earth parametric equations Draw the trajectory after revolutions Matlab 실험·실습과제4