www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/PlacingTextOutsideTheAxesExample.m
%% Display Text Outside Axes % This example shows how to display text outside an axes by creating a % second axes for the text. MATLAB(R) always displays text objects within % an axes. If you want to place a text description alongside % an axes, then you must create another axes to position the text. %% % Create an invisible axes, |ax1|, that encompasses the entire figure % window by specifying its position as |[0 0 1 1]|. Then, create a smaller % axes, |ax2|, to contain the actual plot. Create a line plot in the % smaller axes by specifying |ax2| as an input argument to the |plot| % function. fig = figure; ax1 = axes('Position',[0 0 1 1],'Visible','off'); ax2 = axes('Position',[.3 .1 .6 .8]); t = 0:1000; y = 0.25*exp(-0.005*t); plot(ax2,t,y) %% % Define the text. Use a cell array to create multiline text. descr = {'Plot of the function:'; 'y = A{\ite}^{-\alpha{\itt}}'; ' '; 'With the values:'; 'A = 0.25'; '\alpha = .005'; 't = 0:1000'}; %% % Set the larger axes to be the current axes since the |text| function % places text in the current axes. Then, display the text. axes(ax1) % sets ax1 to current axes text(.025,0.6,descr)