%{ --------- Start of Matlab block comment -------- % Delete the three lines above and the corresponding three lines % below to delete the block commenting that was done during class. %----------------------------------------------------------------------- % A simple script for A321 to illustrate Matlab plotting other than % via the usual plot() function. you can turn echo off if you don't want % to see all of the instructions being executed. % % Randall Bramley % Initiated : Fri 28 Sep 2007, 06:38 PM % Modified : Thu 17 Jul 2008, 03:20 PM, to include staircase % Last Modified: Mon 09 Mar 2009, 11:21 AM %----------------------------------------------------------------------- n = 10; %-------------- % An area plot %-------------- z = -pi:pi/10:pi; figure; area([sin(z); cos(z)]); title('Using Area Plotting') disp('Using Area Plotting') disp('Hit return to continue'); pause; %-------------------- % A simple bar chart %-------------------- x = -3:0.2:3; y = exp(-x.*x); figure; bar(x, y); title('Bar Chart') disp('Bar chart') unstack; disp('Hit return to continue'); pause; %---------------- % A 3D bar chart %---------------- figure; bar3(x, y); title('3D Bar Chart') unstack; disp('3D Bar Chart') disp('Hit return to continue'); pause; %----------------- % A staircae plot %----------------- figure; stairs(x, y); title('Staircase Plot') unstack; disp('Staircase Plot') disp('Hit return to continue'); pause; %--------------------------------------------------- % Disassembled pie chart. % Notice that I used rand, not randn. Try it and % see what Matlab's pie does with the negative data. %--------------------------------------------------- x = rand(n,1); figure; pie(x, x == max(x)); % This distinguishes the largest slice title('pie chart'); unstack; disp('Pie chart'); disp('Hit return to continue'); pause; close all; ----------- End of Matlab block comment -------- %} %------------------------------------------------------------------------ % A drawnow example. Without the pause or drawnow command, all you see is % the last plot. I choice m data points so that when Matlab *does* show % all of the graphs because of a drawnow, they won't zip past too fast % to see. %------------------------------------------------------------------------ n = 24; m = 400000; close all disp('Nex, show 12 iterations of a randn() vector being plotted') figure; for k = 1:n plot(randn(m,1)); title(sprintf('Iteration %d', k)) %------------------------------------------------------ % Need to insert either a pause here (e.g., pause(0.5)) % or the "drawnow" command. %------------------------------------------------------ end unstack; disp('Hit return to continue'); pause; %------------------------------------------------------------------------ % With drawnow: %------------------------------------------------------------------------ n = 24; m = 400000; close all disp('Now, show 12 iterations with drawnow in the loop') figure; disp('resize graphics window if desired, then hit return'); pause; for k = 1:n plot(randn(m,1)); title(sprintf('Iteration %d', k)) drawnow end %------------------------------------------------------------------------ % With pause: %------------------------------------------------------------------------ n = 24; m = 400000; close all disp('Now, show 12 iterations with drawnow in the loop') figure; disp('resize graphics window if desired, then hit return'); pause; for k = 1:n plot(randn(m,1)); title(sprintf('Iteration %d', k)) pause(0.5) end