%% NOTE: this has been written in MATLAB 2009, some of the functionality %% will not be available in older versions of MATLAB! %% WHEN EXECUTING THE ROUTINES IN THIS FILE, PLEASE EXECUTE THEM ONE BY %% ONE, NOT THE WHOLE DOCUMENT AT ONCE... YOU CAN EVALUATE SECTIONS BY %% MARKING THEM AND THEN CHOSING "EVALUATE SELECTION" IN THE RIGHT-CLICK %% MENU %% plot(x) plots against Real numbers %doc plot % Creates row-vector x with numbers from -pi to pi incremented by .1 % pi = -3.14 x = -pi:.1:pi; size(x); % There are 63 elements in x plot(x); % Draws the function y = 0.1x - 3.14 for x in [0 to 63] %% plot(x,Y) plot Y against x Y = sin(x); J = cos(x); clf % clear current figure hold on plot(Y); plot(x,Y); %% Plot more curves in the same figure cla % % clear current axes, hold on is still active plot(Y,J); % Draws a circle cla plot(x,Y,x,J); % Plots the two functions in the same figure hold off % Plotting with vectors as parameters cla A = [Y J]; % A is 1x126 row vector B = [Y;J]; % B is a 2x63 vector plot(A); % sin(x) and cos(x) are attached together, one after another plot(B); % here MATLAB is plotting 63 series of two observations each % The nice figures creates the illusion of multiple curves, try to % zoom-in to see that they all straight ones. % More examples xA = [x;A]; xB = [x B]; plot(xA); plot(xB); plot([xA;x]); %% 2-dimensional range X = [x;x]; plot(X); plot(B,X); % Plots X within the boundaries of B (sin(x) and cos(x)) %% Axis manipulation %doc axis axis([0 2 0 10]); % Set the axis magnitude this way: x[0..2];y[0..10]; plot([xA;x]); % Draws a new plot, overwrite the last axis definition axis([0 2 0 10]); axis manual % Freezes the axis hold on plot([x;xA]); % Only partially visible %% Subplot %doc subplot % subplot(m,n,p) or subplot(mnp) breaks the figure window into an % m-by-n matrix and selects the pth axes object for the current plot, % The axes are counted along the top row of the figure window, then the % second row, etc. %Example: subplot(2,2,1); plot(Y); subplot(2,2,2); plot(A); subplot(2,2,3); plot(X,A); subplot(2,2,4); plot(B); %% GUI Controls plottools