Download presentation
Presentation is loading. Please wait.
Published byJason Burns Modified over 9 years ago
1
Barak Shenhav Early Evolution Course 11 Feb 2001 MATLAB Visualization, Functions & Debugging
2
Visualization
3
Getting Started
4
Creating a Plot x = 0:pi/100:2*pi; y = sin(x); plot(x, y)
5
Multiple Data Sets y2 = sin(x -.25); y3 = sin(x -.5); plot(x, y, x, y2, x, y3) legend('sin(x)', 'sin(x -.25)', 'sin(x -.5)')
6
Line Styles, Colors and Markers plot(x, y, 'r:+') x1 = 0:pi/100:2*pi; x2 = 0:pi/10:2*pi; plot(x1, sin(x1), 'r:', x2, sin(x2), 'r+')
7
Multiple Plots plot(x, y, 'r') figure plot(x, y, 'b') figure(1) plot(x, y, 'g') close all subplot(2, 2, 1); plot(x, y, 'r') subplot(2, 2, 2); plot(x, y, 'b') subplot(2, 2, 3); plot(x, y, 'g') subplot(2, 2, 4); plot(x, y, 'y')
8
Axes Control plot(x, y, x, y2, x, y3) axis([0 2*pi –1 1]) grid on axis auto axis off axis on axis equal axis square
9
Other Plots plot - Graph 2-D data with linear scales for both axes plot3 - Graph 3-D data with linear scales for both axes loglog - Graph with logarithmic scales for both axes semilogx - Graph with a logarithmic scale for the x- axis and a linear scale for the y-axis semilogy - Graph with a logarithmic scale for the y- axis and a linear scale for the x-axis plotyy - Graph with y-tick labels on the left and right side
10
3-D Plot t = 0:pi/50:10*pi; plot3(sin(t), cos(t), t) grid on axis square
11
Labels and Titles x = -pi:pi/100:pi; y = sin(x); plot(x,y) axis([-pi pi -1 1]) ylabel('sin(x)') xlabel('-\pi \leq {\itx} \leq \pi') title('\fontsize{16}Graph of the sine function') text(1,-1/3,'\bf{Note the odd symmetry.}')
12
Get Properties Finding handles: gcf - get current figure handle gca - get current axes handle Getting properties : get(h) - all properties of the graphics object identified by the handle h. get(h, 'PName') - get the value of the property ‘PName' of the graphics object identified by h.
13
Set Properties Setting properties : set(h, ’PName', PValue,...) - sets the named properties to the specified values on the object(s) identified by the handle(s). For example : x = -pi:.1:pi; y = sin(x); plot(x, y) set(gca, 'XTick', -pi:pi/2:pi) set(gca, 'XTickLabel', {'-pi','-pi/2','0','pi/2','pi'})
14
Bar Charts y = round(rand(5,3)*10); subplot(2, 2, 1) bar(Y, 'group') title 'Group' subplot(2, 2, 2) bar(Y, 'stack') title 'Stack' subplot(2, 2, 3) barh(Y, 'stack') title 'Stack' subplot(2, 2, 4) bar(Y,1.5) title 'Width = 1.5'
15
Pie Chart val = [12 17 21]; explode = [0 0 1]; h = pie(val, explode); colormap summer textObjs = findobj(h, 'Type', 'text'); newStr = {'X'; 'Y'; 'Z'}; set(textObjs, {'String'}, newStr)
16
Histogram Y = randn(10000,3); hist(Y)
17
Contour and Quiver n = -2.0:.2:2.0; [X,Y,Z] = peaks(n); [C, h] = contour(X,Y,Z,10); Colormap('default'); clabel(C,h) [U,V] = gradient(Z,.2); hold on quiver(X,Y,U,V) hold off
18
Mesh [U, V] = meshgrid(-8:.5:8); R = sqrt(U.^2 + V.^2) + eps; H = sin(R)./R; mesh(H)
19
Surf surf(X, Y, Z, 'FaceColor', 'interp', … 'EdgeColor', 'none', … 'FaceLighting', 'phong') axis tight view(-50,30) camlight left
20
Movies Z = peaks; surf(Z); axis tight set(gca, 'nextplot', 'replacechildren'); % Record the movie for j = 1:20 surf(sin(2*pi*j/20)*Z, Z) M(j) = getframe; end % Play the movie twenty times movie(M,20)
21
Saving Figures From menu: File Save – MATLAB format File Export – Other graphics formats From command line: Saveas(gcf, filename, extension) Print
22
The Importance of Being Lognormal cLognormal Normal
23
Where Did Life Start ? Life Started Here Q=N/N G
24
020406080100 0 20 40 60 80 100 time 0.15 0.30 0.45 0.60 0.75 0.90 Compositional Carpet
25
Functions function r = rank(A,tol) % RANK Matrix rank. % RANK(A) provides an estimate of the number of % linearly independent rows or columns of a % matrix A. % RANK(A,tol) is the number of singular values of % A that are larger than tol. % By default tol = max(size(A)) * norm(A) * eps. s = svd(A); if nargin==1 tol = max(size(A)) * max(s) * eps; end r = sum(s > tol);
26
MATLAB Components
27
MATLAB Editor
28
Editor Toolbar Step in/over Breakpoint Evaluation Quit The function call stack
29
Strings s1 = 'Hello world 1' s2 = ['Hello ' 'world' ' 2'] s3 = ['Hello world ' num2str(3)] s4 = sprintf('Hello world %d', 4) s5 = ['Hello' ; 'world' ; 'in' ; 'lines'] % ERROR s5 = char({'Hello' ; 'world' ; 'in' ; 'lines'}) % OK
30
Symbolic Math Toolbox-Funtool
31
N G =100 N=30 Percent Compositional Error Catastrophe 0 10 20 30 40 50 60 70 80 90 100 (0.4,0.5) (0.5,0.6) (0.6,0.7) (0.9,1) (0.8,0.9) (0.7,0.8) 0123456 Range of values
32
10 -2 10 -1 10 0 10 1 10 2 0 0.1 0.2 0.3 0.4 0.5 0.6 ** S Q = N NGNG Optimal Assembly Size N ~ 3.5N G
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.