% Example 17.5a (Physics 330) clear;close all; % Make up some data to plot x=0:.01:100; f1=cos(x); f2=exp(-x/20); % Choose what size the entire final figure should be Units = 'Centimeters'; figWidth = 8.5; figHeight = 10; % Create a figure window of a specific size. ff = figure('Units',Units,'Position',[10 10 figWidth figHeight]) % Make the top frame: 2 rows, 1 column, 1st axes subplot(2,1,1) % Make the plot--in this case, we'll just set the lineseries % properties right in the plot command. plot(x,f1,'r-',x,f2,'b--','LineWidth',1.5) % set the plot limits axis([0 100 -1.1 1.1]) % Make the labels. xlabel('x') ylabel('f_1(x), f_2(x)') title('Multiplication of Functions') % Get a handle to the top axes and set the properties of this set of axes aa = gca; set(aa,'FontSize',10,... 'LineWidth',0.75,... 'XTick',[0 20 40 60 80 100],... 'YTick',[-1 -.5 0 .5 1]) % Set this axis to take up the top half of the figure set(aa,'Units',Units,'OuterPosition',[0 figHeight/2 figWidth figHeight/2]) % Now adjust the axes box position to make it fit tightly newPos = get(aa, 'OuterPosition') - ... get(aa, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]; set(aa, 'Position', newPos); % As a finishing touch, draw a proper rectangle around the plot area Bound = annotation(ff,'Rectangle',[0 0 1 1]); set(Bound,'Units',Units,... 'Position',get(aa,'Position'),... 'LineWidth',1); % Create the second set of axes in this figure: 2 rows, 1 column, 2nd axes subplot(2,1,2) % Make the second plot plot(x,f1.*f2,'b-','LineWidth',1.5) % Set labels for second axes xlabel('x') ylabel('f_1(x)* f_2(x)') % Set limits axis([0 100 -1.1 1.1]); % Get a handle for the second axes. Note that we are overwriting % the handle for the first axes, but we're done modifying them, so it's ok aa=gca; % Set properties for the second set of axes set(aa,'FontSize',10,... 'LineWidth',0.75,... 'XTick',[0 20 40 60 80 100],... 'YTick',[-1 -.5 0 .5 1]) % Set this axis to take up the bottom half of the figure set(aa,'Units',Units,'OuterPosition',[0 0 figWidth figHeight/2]) % Now adjust the axes box position to make it fit tightly newPos = get(aa, 'OuterPosition') - ... get(aa, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]; set(aa, 'Position', newPos); % As a finishing touch, draw a proper rectangle around the plot area Bound = annotation(ff,'Rectangle',[0 0 1 1]); set(Bound,'Units',Units,... 'Position',get(aa,'Position'),... 'LineWidth',1);