You are on page 1of 22

MATLAB

n plot :
n x y
x = linspace(0, 2*pi); % 0 2 100
y = sin(x); % x
plot(x, y); %

0.8

0.6

0.4

0.2

-0.2

-0.4
-0.6
(Index)
-0.8

-1
0 1 2 3 4 5 6 7

n x y plot
x = linspace(0, 2*pi); % 0 2 100
plot(x, sin(x), x, cos(x), x, sin(x)+cos(x)); %

1.5

1

0.5
0

-0.5

-1

-1.5
0 1 2 3 4 5 6 7

n
plot(x, sin(x)); hold on; plot(x, cos(x)); hold off;


plot x y (Linear Scale)
loglog x y (Logarithmic Scale)
semilogx x y
semilogy x y
plotyy y
n semilogx
n x
x = linspace(0, 8*pi); % 0 8 100
semilogx(x, sin(x)); % x

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
10
-1 0
10
1
10
2
10 X
n plotyy
n y
x = linspace(0, 2*pi); % 0 2 100
y1 = sin(x);
y2 = exp(-x);
plotyy(x, y1, x, y2); % y y1, y2

1 1

0 0.5

y1 y2
-1 0
0 1 2 3 4 5 6 7

n plot
n
n
plot(x, y, CLM)
n C(Colors)
n L(Line Styles)
n M(Markers)
n
x = 0:0.5:4*pi;
y = sin(x);
plot(x, y,k:diamond) % k
% diamond
%

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 2 4 6 8 10 12 14
plot

Plot RGB
b (Blue) (0,0,1)
c (Cyan) (0,1,1)
g (Green) (0,1,0)
k (Black) (0,0,0)
m (Magenta) (1,0,1)
r (Red) (1,0,0)
w (1,1,1)
y (Yellow) (1,1,0)
plot

plot
- ()
--

-.
plot
plot
O
+
X
*
^
V
>
<
square
diamond
pentagram
hexagram

n plot
n axis
n
axis([xmin, xmax, ymin, ymax])
n xmin , xmax x
n ymin , ymax y
grid box

n

grid on
grid off
box on
box off
n y 0 1
x = 0:0.1:4*pi;
y = sin(x);
plot(x, y);
axis([-inf, inf, 0, 1]); % y 0 1
grid on; %

0.9

0.8

0.7

0.6
inf
0.5 ( x
0.4
)
0.3

0.2

0.1

0
0 2 4 6 8 10 12

n


title
xlabel x
ylabel y
zlabel z ()
legend
text
gtext
n

x = 0:0.1:2*pi; 1
Function Plots of sin(t) and exp(-x)

sin(t)
0.8
y1 = sin(x); exp(-x)

0.6

y2 = exp(-x);

values of sin(t) and exp(-x)


0.4

0.2
plot(x, y1, '--*', x, y2, ':o'); 0

xlabel('time'); -0.2

-0.4
ylabel('values of sin(t) and exp(-x)') -0.6

title('Function Plots of sin(t) and exp(-x)'); -0.8

-1

legend('sin(t)','exp(-x)');
0 1 2 3 4 5 6 7
time
n text
n
text(x, y, string)
n xy
n string
1

0.8

x = 0:0.1:2*pi; 0.6

plot(x, sin(x), x, cos(x)); 0.4

0.2

text(0.2, 0, 'sin(x)') 0 sin(x) cos(x)

text(0.5*pi+0.2, 0, 'cos(x)') -0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7
n gtext
n
gtext(string)
n string
n gtext

n subplot
n ()
n subplot (m, n, p)
n m n
n plot p
n p

n
x = 0:0.1:4*pi;
subplot(2, 2, 1); plot(x, sin(x)); %
subplot(2, 2, 2); plot(x, cos(x)); %
subplot(2, 2, 3); plot(x, sin(x).*exp(-x/5)); %
subplot(2, 2, 4); plot(x, x.^2); %
1 1

0.5 0.5

subplot(2,2,1) 0 0
subplot(2,2,2)
-0.5 -0.5

-1 -1
0 5 10 15 0 5 10 15

1 200

150
0.5
100
subplot(2,2,3) 0 subplot(2,2,4)
50

-0.5 0
0 5 10 15 0 5 10 15
- errorbar
n errorbar:
n y 20%
x = linspace(0,2*pi,30); % 0 2 30
y = sin(x);
e = y*0.2;
errorbar(x,y,e) % e
1.5

0.5

-0.5

-1
-1.5
-1 0 1 2 3 4 5 6 7
- fplot
n fplot:
n

fplot('sin(1/x)', [0.02 0.2]); % [0.02 0.2]

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2

You might also like