Microsoft PowerPoint - Introduction to Matlab 4

Microsoft PowerPoint - Introduction to Matlab 4 - MATLAB...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB MATLAB PART PART PART PART PART PART PART PART 4 PREPARED PREPARED PREPARED PREPARED BY BY BY BY S. M. S. M. S. M. S. M. RAFIGH RAFIGH RAFIGH RAFIGH 2011 2011 2011 2011 COURSE BY : PROF. COURSE BY : PROF. COURSE BY : PROF. COURSE BY : PROF. HOSSEINI HOSSEINI HOSSEINI HOSSEINI MATLAB GRAPHICS r One of the best things about MATLAB is interactive graphics r “ plot ” is the one you will be using most often any other plotting functions lot r Many other 3D plotting functions -- plot3, mesh, surfc, etc. r Use “ help plot ” for plotting options r To get a new figure, use “ figure ” r logarithmic plots available using semilogx, semilogy and loglog plot(x,y) defaults to a blue line plot(x,y,’ro’) uses red circles plot(x,y,’g*’) uses magenta asterisks Plotting Commands Plotting Commands If you want to put two plots on the same graph, use “ hold on ” plot(a,b,’r:’) (red dotted line) hold on plot(a,c,’ko’) (black circles) plot (x, y) plot(x1, y1, x2, y2) plot (x, y, ‘color symbol line style ’) » x = linspace(0, 2*pi); » y = sin (2.*x); Plotting Commands Plotting Commands » z = cos (0.5*x); » plot (x, y) » plot (x, y, x, z) » figure (2) » plot (x, y, 'r o -'); grid on » hold on » plot (x, z, 'b * :') (red, circle, solid line) (blue, star, dotted line) figure or figure (#) : open a figure xlabel ( ′′ ′ label ′′ ′ ) ylabel ( ′′ ′ label ′′ ′ ) title ( ′′ ′ title of the plot ′′ ′ ) text ( x_location, y_location, ′′ ′ text ′′ ′ ) axis ( [ x_min x_max y_min y_max ] ) Graphics Commands Graphics Commands • Axis, Labels, and Title » xlabel ( ′′ ′ Time ′′ ′ ) » ylabel ( ′′ ′ Temperature ′′ ′ ) » title ( ′′ ′ Temperature Record : 1900 - 2000 ′′ ′ ) » text (17, 120, ′′ ′ Record High ′′ ′ ) » text (85, -40, ′′ ′ Record Low ′′ ′ ) » axis ([0 100 -50 140]) » hold off ′′ ′ ′ ′′ ′- text string Color, Symbols, and Line Types Color, Symbols, and Line Types r Use “help plot” to find available Specifiers b blue . point - solid g green o circle : dotted r red x x-mark -. dashdot c cyan + plus -- dashed Colors Symbols Line Types m magenta * star y yellow s square k black d diamond v triangle (down) ^ triangle (up) < triangle (left) > triangle (right) p pentagram h hexagram » x=0:0.1:5; » y=2*x.^3-12*x.^2+8*x-6; » H=plot(x,y,'b',x,y,'r*'); » set(H,'LineWidth',3,'MarkerSize',12) » xlabel('x'); ylabel('y'); » title('f(x)=2x^3-12x^2+8x-6'); » print -djpeg075 poly.jpg Adjust line thickness, font size, marker size, etc. element-by-element operations x.^n » x=0:0.1:10; » y=sin(2.*pi*x)+cos(pi*x); » H1=plot(x,y,'m'); set(H1,'LineWidth',3); hold on; » H2=plot(x,y,'bO'); set(H2,'LineWidth',3,'MarkerSize',10); hold off; » xlabel('x'); ylabel('y'); » title('y = sin(2\pix)+cos(\pix)'); » print -djpeg075 function.jpg » x=0:0.1:3; y1=exp(-x); y2=sqrt(x); » H=plot(x,y1,'b-',x,y2,'r--');...
View Full Document

This note was uploaded on 06/21/2011 for the course ME 2072 taught by Professor Prof. hosseini during the Winter '09 term at Sharif University of Technology.

Page1 / 58

Microsoft PowerPoint - Introduction to Matlab 4 - MATLAB...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online