Professional Documents
Culture Documents
t = 0:0.1:2*pi;
x = 2 * cos(t);
y = 2 * sin(t);
plot(x, y);
1
축(axis) 속성
아래와 같이 타원형 그래프를 그려서, axis equal 과 axis square가
어떻게 다른지 확인해 봅시다.
t = 0:0.1:2*pi;
x = 2 * cos(t);
y = 4 * sin(t);
plot(x, y);
2
축(axis) 속성
아래와 같이 타원형 그래프를 그려서, axis equal 과 axis square가
어떻게 다른지 확인해 봅시다.
axis square
3
축 눈금 표시
축의 속성 ‘xtick’, ‘xticklabel’ 변경
x = 0:0.1:2*pi;
xlabel = linspace(0, 2*pi, 5);
w = '0 pi|0.5 pi|1 pi|1.5 pi|2 pi';
plot( x, sin(x) );
set(gca, 'xtick', xlabel, 'xticklabel', w);
4
Handle Graphics Object
한 그래프는 여러 그래픽 오브젝트들의 조합으로 만들어짐
Axes Object
Text Object
• Handle이란?
– MATLAB이 그래픽 오브젝트에 부여하는 고유의 식별 아이디
• Handle은 왜 필요한가?
– 그래프 figure가 여러 개 생성되어 있을 때, 첫 번째 figure의 속성을 바꾸고 싶다면?
– 첫 번째 figure의 handle로 접근이 가능
5
Handle Graphics Object
set 함수
• 매개변수로 지정한 그래픽 오브젝트의 속성을 변경
Figure의
Handle
특성 이름
(propertyname)
특성 값
(propertyvalue)
6
propertynames, propertyvalues
>> set(1)
Alphamap
CloseRequestFcn: string -or- function handle -or- cell array
Color
Colormap
CurrentAxes
CurrentCharacter
CurrentObject
CurrentPoint
DockControls: [ {on} | off ]
FileName
IntegerHandle: [ {on} | off ]
InvertHardcopy: [ {on} | off ]
KeyPressFcn: string -or- function handle -or- cell array
KeyReleaseFcn: string -or- function handle -or- cell array
MenuBar: [ none | {figure} ]
Name
NextPlot: [ new | {add} | replace | replacechildren ]
NumberTitle: [ {on} | off ]
PaperUnits: [ {inches} | centimeters | normalized | points ]
PaperOrientation: [ {portrait} | landscape | rotated ]
PaperPosition
PaperPositionMode: [ auto | {manual} ]
PaperSize
PaperType: [ {usletter} | uslegal | A0 | A1 | A2 | A3 | A4 | A5 | B0 | B1 | B2 | B3 | B4 | B5 | arch-A | arch-B | arch-C | arch-D | arch-E | A | B | C | D | E | tabloid | <custom> ]
Pointer: [ crosshair | fullcrosshair | {arrow} | ibeam | watch | topl | topr | botl | botr | left | top | right | bottom | circle | cross | fleur | custom | hand ]
PointerShapeCData
PointerShapeHotSpot
Position
Renderer: [ {painters} | zbuffer | OpenGL | None ]
RendererMode: [ {auto} | manual ]
Resize: [ {on} | off ]
ResizeFcn: string -or- function handle -or- cell array
SelectionType: [ normal | open | alt | extend ]
ToolBar: [ none | {auto} | figure ]
Units: [ inches | centimeters | normalized | points | {pixels} | characters ]
WindowButtonDownFcn: string -or- function handle -or- cell array
WindowButtonMotionFcn: string -or- function handle -or- cell array
WindowButtonUpFcn: string -or- function handle -or- cell array
WindowKeyPressFcn: string -or- function handle -or- cell array
WindowKeyReleaseFcn: string -or- function handle -or- cell array
WindowScrollWheelFcn: string -or- function handle -or- cell array
7
그래픽 오브젝트 속성 변경해보기
8
특정 Handle을 가리키는 변수
gcf (get current figure )
• 현재 활성화 되어있는 figure window의 handle값을 갖고 있는 변수
9
특정 Handle을 가리키는 변수
>> t = -2:0.01:2;
>> y1 = t .^ 2;
>> y2 = t .^ 3;
>> plot( t, y1, t, y2 )
파란색 선 마우스로 선택
10
좌우 Y축 범위 다르게 plot
plotyy( X1, Y1, X2, Y2 )
x = 0:0.1:1;
plotyy(x, sin(x), x2, 10*cos(x));
11
여러 그래프를 하나의 그림에 나타내기
subplot(m, n, p) 또는 subplot(mnp)
• 그림을 m x n 영역로 나누고, p번째 영역에 plot
subplot(2, 2, 1);
x = 0:0.1:2*pi;
plot( x, sin(x) );
subplot(2, 2, 2);
x = 0:0.1:10;
plot( x, sin(round(x)) );
1 2
subplot(2, 2, 3);
x = 0.01:0.01:2*pi;
plot( x, sinc(x) ); 3 4
subplot(2, 2, 4);
x = 0:0.1:2*pi;
plot( x, sin(x) );
hold on;
plot( x, cos(2*x) ); 12
여러 그래프를 하나의 그림에 나타내기
subplot(2, 2, [1 3]);
x = 0:0.1:2*pi;
plot( x, sin(x) );
subplot(2, 2, 2);
x = 0:0.1:10;
plot( x, sin(round(x)) );
subplot(2, 2, 4);
x = 0:0.1:2*pi;
plot( x, cos(2*x) );
13
Quiz
이전 슬라이드의 그래프와 다르게, 첫 번째 그래프가 가로로 넓게 펼쳐진 형태의
figure를 만들어 봅시다.
14
축 방향 거꾸로 만들기
set(gca, ‘xdir’ 또는 ’ydir’ 또는 ’zdir’, ‘rev’)
t = 0:0.1:2*pi;
subplot(1, 2, 1);
plot( t, sinc(t) );
subplot(1, 2, 2)
plot( t, sinc(t) );
set( gca, 'xdir', 'rev' );
15
grid on/off 외의 속성들
xgrid, ygrid, zgrid : 각각의 좌표축에만 grid 설정
gridlinestyle : grid 라인의 스타일 변경
t = 0:0.001:1;
y = exp(-20*t) .* sin(200*t);
plot(t, y);
set(gca, 'xgrid', 'on', 'gridlinestyle', '-.');
16
곡선과 눈금 모양 설정
plot 함수에서 선의 굵기, marker의 크기 및 색상, 폰트의 크기 등을
설정 가능
plot 함수 옵션 기본값
LineWidtn 0.5
MarkerSize 6
MarkerEdgeColor auto
MarkerFaceColor none
FontSize 10
FontAngle normal
17
ez* 그래프 드로잉 함수들
18
ez* 함수
19
ezplot (2D plotter)
20
ezplot (2D plotter)
21
ezplot (2D plotter)
22
ezplot3 (3D plotter)
23
ezplot3 (3D plotter)
24
ezplot3 (3D plotter)
25
ezcontour
26
Quiz
27
ezcontourf
28
ezcontourf
29
ezsurf
30
ezsurf
31
ezsurf
32
ezsurfc
33
Quiz
34
Quiz Sol.
35
ezmesh, ezmeshc
36
ezpolar (polar coordinate plotter)
37
2D 그래프 드로잉 함수들
38
bar 그래프
subplot(3,1,1);
bar( rand(10,5), 'stacked‘ );
subplot(3,1,2);
bar( 0:.25:1, rand(5), 1);
subplot(3,1,3);
bar( rand(2,3), .75, 'grouped‘ );
39
bar 그래프
수능 등급 별 학생수
수능등급 1반 2반 3반
1등급 5 7 4
2등급 12 11 15
3등급 19 20 17
4등급 7 6 5
5등급 2 1 3
40
bar3 그래프
수능 등급 별 학생수
수능등급 1반 2반 3반
1등급 5 7 4
2등급 12 11 15
3등급 19 20 17
4등급 7 6 5
5등급 2 1 3
41
hist 그래프
r = hist( Y )
• 입력 데이터 Y의 범위를 균일하게 10등분
하여 해당 범위 내에 속하는 원소들을 count
r = hist( Y, k )
• 입력 데이터 Y의 범위를 균일하게 k등분 하여
해당 범위 내에 속하는 원소들을 count
42
area 그래프
43
pie 그래프
x = [1 2 3 4 5];
y = [16 38 56 18 6];
pie(x, y);
legend('grade 1', 'grade 2', 'grade 3', 'grade 4', 'grade 5', -1);
44
pie3 그래프
h = pie3( X )
• 배열 X를 구성하는 각각의 원소들을 하나의 조각으로 표현
h = pie3( X, explode )
• explode의 nonzero에 있는 조각을 pie chart 중심에서 이탈시켜 표현
45
계단 모양 그래프
이산 데이터 표시 등에 사용될 수 있는 그래프
>> x = 0:0.1:2*pi;
>> y = sin(x);
>> stairs( y );
46
stem 그래프
이산 신호 임펄스 응답 나타낼 때 이용
>> x = 0:0.1:2*pi;
>> y = sin(x);
>> stem( y );
47
errorbar 그래프
데이터의 신뢰도 표시에 사용되는 그래프
• 오차 데이터 지정해야 함
>> x = 0:0.5:2*pi;
>> y = sin(x);
>> lowlimit = 0.1*ones(size(x));
>> highlimit = 0.3*ones(size(x));
>> errorbar(x, y, lowlimit, highlimit);
48
Quiz
49
Quiz Sol.
x = -2:0.01:2;
n = 100;
f = zeros(1, length(x));
for k=1:2:n
f = f + sin(pi*k*x)/k;
end
plot(x,f);
50
Plot Editing
51
Plot Editing
그래프 회전, 텍스트 레이블, 화살표, 도형, …
52