1. plot(x,y) x=10; y=20; plot(x,y) will 2d plot a point at Euclidean with x coordinate x and y coordinate y i.e. point (10,20). plot(y,x) is confusing: the x coordinate of the point is y and the y coordinate is x i.e. point (20,10) will be plotted. By default, MATLAB marks the point with a period in blue color. plot([1 2],[3 5],'rs-') can additionally specify as a strings or array - points (1,3) and (2,5) with the form of an array of x values [ 1 2 ] and y values [3 5] - points will be marked with s (square) and in red. - points will be connected with straight lines Alternatives to 'rs-' are drawsn from the three lists belows T1. COLOR symbols in plot string ***************************** A one character color code such as : r (red) k (black) g,b,m,y,c,y T2. MARKER symbols in plot string ****************************** A marker for the points such as . o x + * s d v ^ < > p h nomarker (see page 6 of Sub5) T3. LINE type connecting ************************ A line style that connects the points such as nothing, - : -. -- For a plot of multiple points generate row vectors >> x= -pi:pi/10:pi; >> y=sin(x); >> z=cos(x); >> w=sin(x) .* sin(x) % note the array operator plot(x,y) % plots a sin function >> grid on ; % to add grid lines >> grid off ; % to turn them off >> axis on ; % default >> axis off ; % no axes >> axis normal >> axis equal >> axis square >> axis ( [ -10 10 -2 2 ] % [ xmin xmax ymin ymax] >> % Add title and labels >> title('My first plot'); >> xlabel('x') >> ylabel('y'); >> %add color to title >> title('\color{red}My first plot'); >> title('\color[rgb]{1.0 0.0 0.0}My first plot'); % Read MiniProject 1 for rgb attributes. Note for a jpeg image values are say from 0 to 255 % but for color the three values are between 0 and 1 >> % If all else fails right click with the mouse and choose Font or Color ! >> % Add a legend >> legend('sin(x)','Location','Best'); % Instead of Best try North , South etc, NorthEast but NorthEastOutside (note capitalization) >> T4. Other functions other plots ******************************* axis on axis off axis normal axis auto axis equal axis square axis([xmin xmax ymin ymax]) title(titlestring); xlabel(titlestring); ylabel(titlestring); titlestring is a string that can contai '... \color{red}xyz\color{blue}abcd ... ' Note that colors now are not SINGLE characters but full words. ALternative to color \color[rgb]{r g b} (Note braces and brackets) where r g b are between 0 and 1 (inclusive) not 0 and 255 (for images) legend(stringlegend, 'Location', LocationString); LocationString in textbook are wrong Examples for LocationString 'Best' 'East' 'EastOutside' 'NorthEast' 'NorthEastOutside' and variations. Capititalization as indicated is IMPORTANT. plot : 2D plot plot3: 3D plot semilogx : log-x but standard y semilogy : log-y but standard x loglog : log-x and log-y more on plot plot(x,y,string,'LineWidth', 3, 'MarkerSize', 6, 'MarkerEdgeColor','r','MarkerFaceColor','g'); 2. Two plots at at time in one figure or multiple figures >> plot(x,y,x,z) % Plot x vs y first plot and x vs z second plot % Note x is the x vector because it is first / third % Note y is the y vector because it is second of the first pair x,y % Note z is the y vector because it is second of the second pair x,z >> plot(y,x,z,x) % the y vectors are the x and the x vectos are the y,z >> % Default figure name is Figure 1 >> % Change figure label >> figure(2) >> plot(x,y); % again sin(x) >> figure(1) % go back to figure 1 >> plot(x,z) % now it's cos(x) >> figure(2) %back to 2 >> axis off >> axis on; >> figure(1) >> grid on >> grid off % we are still in figure (1) % if plot(x,w) we overwrite the plot(x,z) % >> hold on % hold on first plot % add a second plot >> plot(x,w) 3. Subplot : Multiple plots in one figure separately >> subplot(2,3,1) % split screen of Figure into a matrix 2x3 and number six areas row-major % 1 is top-left >> plot(x,y); >> subplot(2,3,6) % bottom right >> plot(y,x) >> figure(2); >> subplot(1,3,1) >> plot(x,w) 4. plot3, semilogx, semilogy, loglog A 3d plot requires x,y,z >> plot3(x,y,z) % Which one is the x axis? >> xlabel('x'); >> ylabel('y'); >> zlabel('z'); >> semilogx(x,y) % plots log(x) vs y not x vs y x>=0 % For sin(x) only a fraction of the points are plotted % Which ones >> semilogx(x,y,'s') % Countthem >> % Or sum(x>0) >> axis auto >> axis 'auto xz' 5. Greek letters and symbols. Text and Tex/Latex Symbox >> text(10,10, '\Lambda\Omega\Xi'); >> text(10,10, '\Theta\epsilon\varepsilon'); >> text(10,10, '\Rightarrow\rightarrow'); >> text(10,10, '\bf Bold Face \sl Slanted \rm Roman \it Italics'); >> text(2,2, '\fontname{roman} Roman \fontname{times} Times \fontname{courier} Courier'); >> text(3,3, '\fontsize{16}\fontname{roman} Roman \fontname{times} Times \fontname{courier} Courier'); Fancier >> % Some fonts do not support large fonts >> title('x^y x_z x^y_z'); >> xlabel('n \rightarrow \infty'); >> plot(x,y,'b-o','LineWidth',3,'MarkerSize',6,'MarkerEdgeColor','r','MarkerFaceColor','b'); T5. Text and tex **************** text(x,y,string) as in text(10,20,'mytext'); text(10,30,'\color{red}redtext'); text(x,y,'\rightarrow\Rightarrow'); Words starting with \ are TeX or LaTeX symbols you could use \cap : set intersection \cup : set union \in : belongs \forall \exists \epsilon \varepsilon \theta \eta \zeta \vartheta usually surrounded also by $ The post powerful command is x=10; y=20; tex('pos',[x y],'interpreter','latex','string','$\epsilon = \frac{x}{y}$'); It use Latex to type a fraction with numerator x and denominator y. More on Tex Latex goto Google . T6. Print ********* print -djpeg myplot : output figure in a file named myplot as jpeg image -deps : PostScript Encapsulated -depsc : PostScript Encapsulated Color -djpeg : Jpeg -dpng : Png -dtiff : Tiff 6. Polar plots! polar plots theta = -pi:pi/10:pi; r = 10*ones(1,length(theta)); >> theta = -pi:pi/100: pi; >> r=sqrt(sin(2.0 .* theta)); >> polar(theta,r); >> polar(theta, sin(3.0 .* theta)); >> polar(theta, 1+ cos(theta)); >> polar(theta, theta .* 6 / pi); >> polar(theta, sin(theta) .* cos(theta)); 7. Plot a circle in MATLAB. x= r cos(theta) y= r sin(theta) (x,y) are the points of the circle. >> theta = -pi:pi/20:pi >> r=10 >> x = r .* cos(theta); >> y = r .* sin(theta); >> plot(x,y); % Change center from (0,0) to (10,20) >> x = x +10; >> y = y +20; >> plot(x,y); 8. Help! >> doc text >> help text 9. Plot review >> plot(x,y,x,z) % Plot x vs y first plot and x vs z second plot % Note x is the x vector because it is first / third % Note y is the y vector because it is second of the first pair x,y % Note z is the y vector because it is second of the second pair x,z >> plot(y,x,z,x) % the y vectors are the x and the x vectos are the y,z Subplot : Multiple plots in one figure separately >> subplot(2,3,1) % split screen of Figure into a matrix 2x3 and number six areas row-major % 1 is top-left >> plot(x,y); >> subplot(2,3,6) % bottom right >> plot(y,x) >> figure(2); >> subplot(1,3,1) >> plot(x,w) plot3, semilogx, semilogy, loglog A 3d plot requires x,y,z >> x=-pi:pi/20:pi; % What if i write x=-pi:pi/20;pi ? >> y=sin(x); >> z=cos(x); >> plot3(x,y,z) >> semilogx(x,y) % plots log(x) vs y not x vs y x>=0 % For sin(x) only a fraction of the points are plotted % Which ones >> semilogx(x,y,'s') % Countthem >> % Or sum(x>0) >> axis 'auto xz' Greek letters and symbols >> text(10,10, '\Rightarrow\rightarrow'); >> text(10,10, '\bf Bold Face \sl Slanted \rm Roman \it Italics'); >> text(2,2, '\fontname{roman} Roman \fontname{times} Times \fontname{courier} Courier'); >> text(3,3, '\fontsize{16}\fontname{roman} Roman \fontname{times} Times \fontname{courier} Courier'); >> plot(x,y,'b-o','LineWidth',3,'MarkerSize',6,'MarkerEdgeColor','r','MarkerFaceColor','b'); Polar plots! polar plots >> r = 10*ones(1,length(theta)); >> theta = -pi:pi/100: pi; >> polar(theta, sin(3.0 .* theta)); Plot a circle in MATLAB. >> theta = -pi:pi/20:pi >> r=10 >> x = r .* cos(theta); >> y = r .* sin(theta); >> plot(x,y); T6. HOW TO CHANGE TICK SYMBOLS , SPACING ON A FIGURE/PLOT IN MATLAB; Say we have >> x= -pi:pi/20:pi; >> y= sin(x); >> plot(x,y); % If you don't like the plotting, you can overwrite it as follows. >> set(gca, 'XLim', [-4 4] ); % This has no effect since -4 to 4 IS THE RANGE ANYWAY >> set(gca, 'XTick', [-4:2:4]); % The ticks are going to be at -4 -2 0 2 4 then >> set(gca, 'XTickLabel', ['0'; ''; '1' ; '' ; '2' ]); % We change to have symbols % 0 1 and 2 as markers at -4 0 and 4 respectively and no mark at -2 and 2. % This way we can have a list of any marker at the Ticks % If X is replaced by Y or Z we can do the same for the y-axis and z-axis respectively. T7. LEGEND OPTIONS (NOTE THAT THE TEXTBOOK PROVIDES INCORRECT (OLD) INFORMATION 'North' inside plot box near top 'South' inside bottom 'East' inside right 'West' inside left 'NorthEast' inside top right (default for 2-D plots) 'NorthWest' inside top left 'SouthEast' inside bottom right 'SouthWest' inside bottom left 'NorthOutside' outside plot box near top 'SouthOutside' outside bottom 'EastOutside' outside right 'WestOutside' outside left 'NorthEastOutside' outside top right (default for 3-D plots) 'NorthWestOutside' outside top left 'SouthEastOutside' outside bottom right 'SouthWestOutside' outside bottom left 'Best' least conflict with data in plot 'BestOutside' least unused space outside plot