matlab tutorial chapter 3

Post on 23-Jun-2015

693 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Matlab Tutorial Chapter 3

TRANSCRIPT

COMLABS Computer Laboratory

TEKNIK VISUALISASI DATA PADA MATLAB

1. Pembuatan Grafik

atlab yang dikenal dengan Matrix Laboratory sering sekali

digunakan dalam pengolahan data dalam bentuk grafik. Hal

ini yang memberikan keunikan tersendiri yang dimiliki oleh

matlab dalam mengolah data baik dalam bentuk teks, gambar

atau grafik dan suara.

Pada pembahasan sebelumnya dasar-dasar pembuatan grafik sudah

dijelaskan, dan pada pembahasan kali ini akan diperdalam dalam

penggunaan matlab untuk mengoptimalkannya dalam pembuatan grafik 2D

hingga 3D.

Plot

Plot merupakan sebuah fungsi yang dimiliki oleh matlab yang biasa

digunakan untuk menggambarkan data dalam bentuk grafik dua(2)

dimensi.

Plot3

Plot3 merupakan sebuah fungsi lainnya yang dimiliki matlab untuk

dapat menggambarkan data dalam bentuk grafik tiga(3) dimensi

dengan variabel pembentuk x,y,z.

Beberapa fungsi lainnya terdapat juga pada matlab dalam

membentuk grafik 3D diantaranya adalah surf, mesh, meshgrid,

surface, dan lain sebagainya.

Terdapat beberapa cara untuk menambahkan keterangan maupun

pengaturan untuk tampilan grafik yakni :

title(‘string’)

xlabel(‘string’)

ylabel(‘string’)

axis([xmin xmax ymin ymax])

grid

legend

subplot(m,n,p)

get(gca,’property’)

set(obj,’property’,value)

text

figure(index)

0

10

20

30

40

0

10

20

30

40

-0.4

-0.2

0

0.2

0.4

0.6

0.8

1

COMLABS Computer Laboratory

Contoh :

title('Grafik Pemetaan Pertumbuhan Penduduk');

xlabel('Tahun');

ylabel('Jumlah Penduduk');

legend('Penduduk','Kota');

grid on atau grid off

hold on atau hold off

surf(peaks(40));

surf(membrane);

Lampiran

Contoh 1

Contoh 2

t=0:0.05:10; sinus=sin(2*pi*0.1*t); kotak=square(2*pi*0.25*t); gigi=sawtooth(2*pi*0.25*t); subplot(2,2,1); plot(t,sinus), title('sinus 1/10 Hz') subplot(2,2,2); stem(t,sinus), title('sinus 1/10 Hz') subplot(2,2,3); plot(t,kotak), title('kotak 1/4 Hz') subplot(2,2,4); plot(t,gigi), title('gigi gergaji 1/4 Hz')

plot(0:pi/20:2*pi,sin(0:pi/20:2*pi)) text(pi,0,' \leftarrow sin(\pi)','FontSize',18) text(3*pi/4,sin(3*pi/4),... ['sin(3*pi/4) = ',num2str(sin(3*pi/4))],... 'HorizontalAlignment','center',... 'BackgroundColor',[.7 .9 .7]); %{ text(3*pi/4,sin(3*pi/4),... '\leftarrowsin(t) = .707',... 'EdgeColor','red'); %}

COMLABS Computer Laboratory

Contoh 3

Contoh 4

Contoh 5

Contoh 6

Contoh 7

Contoh 8

Contoh 9

Contoh 10

t = 0:0.01:10*pi; x = t.*sin(t); y = t.*cos(t); axislimits = [min(x) max(x) min(y) max(y) min(t) max(t)]; line_handle = plot3(x(1), y(1),t(1), 'go', ... 'MarkerFaceColor',[.49 1 .63], 'MarkerSize',12); %set(line_handle, 'erasemode','xor'); axis(axislimits); grid on for i = 2:length(x)

set(line_handle, 'xdata',x(i), 'ydata', y(i),... 'zdata', t(i));

drawnow; end

data = [100 500 80 150]; pie(data,{'Gol I','Gol II','Gol IV','Gol III'})

[X,Y] = meshgrid(-2:.2:2, -2:.2:2); Z = X .* exp(-X.^2 - Y.^2); surf(X,Y,Z)

t = 0:0.01:10*pi; x = t.*sin(t); y = t.*cos(t); axislimits = [min(x) max(x) min(y) max(y) min(t) max(t)]; plot3(x,y,t); axis(axislimits); %axis square grid on

t=linspace(-2*pi,2*pi,10); h=stem(t,cos(t),'fill','--'); set(get(h,'BaseLine'),'LineStyle',':') set(h,'MarkerFaceColor','red')

data = rand(10,5); bar3(data,'stacked'); colormap(cool);

sphere(20) shading interp shading flat shading faceted axis equal

[x,y] = meshgrid(1:5,1:5); z = rand(5,5); stem3(x,y,z,'MarkerFaceColor','g')

COMLABS Computer Laboratory

Contoh 11

Contoh 12

Contoh 13

Contoh 14

Contoh 15

x=linspace(0,5,500); y1=exp(-x); y2=exp(-0.5*x); y3=exp(-0.25*x); y4=exp(-0.1*x); subplot(1,2,1); plot(x,y1,x,y2,x,y3,x,y4) grid on xlabel('sumbu-x'), ylabel('sumbu-y') title('Kurva y = exp(-Ax)') legend('A=1','A=0.5','A=0.25','A=0.1') subplot(1,2,2); semilogy(x,y1,x,y2,x,y3,x,y4) grid on xlabel('sumbu-x'), ylabel('sumbu-y') title('Kurva y = exp(-Ax)') legend('A=1','A=0.5','A=0.25','A=0.1') axis([0 5 1e-2 1])

theta=linspace(0,2*pi,500); rho=(cos(theta.*3)).^2; polar(theta,rho);

batas_x = -10:1:10; batas_y = -10:4:10; [X,Y] = meshgrid(batas_x,batas_y); Z = X.^2 + Y.^2; subplot(2,2,1); mesh(X,Y,Z); subplot(2,2,2); surf(X,Y,Z); subplot(2,2,3); contour(X,Y,Z); subplot(2,2,4); meshc(X,Y,Z);

cylinder axis square h = findobj('Type','surface'); set(h,'CData',rand(size(get(h,'CData'))))

t = 0:pi/10:2*pi; [X,Y,Z] = cylinder(2+cos(t)); surf(X,Y,Z) axis square

top related