English | Español

# Try our Free Online Math Solver! Online Math Solver

 Depdendent Variable

 Number of equations to solve: 23456789
 Equ. #1:
 Equ. #2:

 Equ. #3:

 Equ. #4:

 Equ. #5:

 Equ. #6:

 Equ. #7:

 Equ. #8:

 Equ. #9:

 Solve for:

 Dependent Variable

 Number of inequalities to solve: 23456789
 Ineq. #1:
 Ineq. #2:

 Ineq. #3:

 Ineq. #4:

 Ineq. #5:

 Ineq. #6:

 Ineq. #7:

 Ineq. #8:

 Ineq. #9:

 Solve for:

 Please use this form if you would like to have this math solver on your website, free of charge. Name: Email: Your Website: Msg:

# INTRODUCTION TO MATLAB

17.4 Making an EPS Suitable for Publication
The sizing commands in Example 17.3a fixed our scaling problem, but the figure still needs
a lot of improvement before it would be suitable for a thesis or journal. For instance, we
still need to fix the axes limits and put on labels. The lines are still sort of "spidery," and
the x-axis is labeled with integers rather than fractions of π. We also need to provide a
legend that tells what the lines and dots on this plot mean . In Example 17.4a we show how
to address all of these issues by setting the visual properties of the objects on the figure.
Run this example and then study the comments in it. The EPS output (made using "Save
as") produced by this example is included as Fig. 17.3.

 Example 17.4a (ch17ex4a.m) %Example 17.4a (Physics 330) clear;close all; x=0:0.05:2*pi; f=sin(x); data = f + rand(1,length(x))-0.5; err_hi = f + 0.5; err_low = f - 0.5; % Choose what size the final figure should be Units = 'Centimeters'; figWidth = 8.5; figHeight = 7; % Create a figure window of a specific size. % Note that we also get a handle to the entire figure (ff) for later use ff = figure('Units',Units,'Position',[10 10 figWidth figHeight]) % Plot the data and get handles to the lineseries objects. pp=plot(x,f,'b',x,data,'b.',x,err_hi,'r-.',x,err_low,'g--'); % Set the lineseries visual properties. set(pp(1),'LineWidth',2); % Make the main sine a heavy line set(pp(2),'MarkerSize',8); % Make the dots a bit bigger than default set(pp(3),'LineWidth',1); % Make the error bound lines slightly heavier set(pp(4),'LineWidth',1); % Make the error bound lines slightly heavier % Set the plot limits and put on labels axis([0 2*pi -1.6 1.6]) xlabel('\theta') ylabel('sin(\theta)') title('Fake measurement of Sine function') % Get a handle to the axes and set the axes visual properties aa=gca; set(aa,'FontSize',8,... % Set the font for the axes 'FontName','Symbol',... % to get pi in labels (p is pi in symbol font ) 'LineWidth',1,... % Make the border around the figure heavier 'TickLength',get(aa,'TickLength')*2,... 'XTick',[0 pi/2 pi 3*pi/2 2*pi],... % Specify where the ticks go 'XTickLabel',{'0';'p/2';'p';'3p/2';'2p'},... % custom tick labels 'XMinorTick','On',... 'YTick',[-1 -.5 0 .5 1],... 'YMinorTick','On') % Put in a legend. We have to specify the font back to Helvetica (default) % because we changed to the symbol font above for the pi tick labels. ll=legend('Sine','Fake Data','Upper Limit',' Lower Limit '); set(ll,'FontName','Helvetica') % Set the output size for the figure. % DO THIS LAST because the margins will depend on font size, etc. % Set the outside dimensions of the figure. set(aa,'Units',Units,'OuterPosition',[0 0 figWidth figHeight]) % Calculate where the axes box should be placed inside the overall figure. newPos = get(aa, 'OuterPosition') - ... get(aa, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]; % Now set the position of the axes box within the figure set(aa, 'Position', newPos); % As a finishing touch, draw a proper rectangle around the plot area % (The box matlab draws has lines that don't join in sharp corners...) Bound = annotation(ff,'Rectangle',[0 0 1 1]); set(Bound,'Units',Units,... 'Position',get(aa,'Position'),... 'LineWidth',1); Figure 17.3 Plot made in Example 17.2b (no scaling).

Although the code is (of course) more complicated, it does make a graph that 's suitable
for publication. The FontName business can be removed if you are not trying to get symbols
as tick labels (unfortunately you can't use Matlab's TEX capabilities for tick labels). You
may have also noticed that the example used the get command, which allows you to read
the current value of a property from one of the objects that you are controlling.

17.5 Subplots
In technical writing, it is often desirable to put multiple plots in the same figure. The
command to produce plots like this is subplot , and the syntax is:
subplot (rows,columns,plot number)

This command splits a single figure window into an array of subwindows, the array having
rows rows and columns columns. The last argument tells Matlab which one of the windows
you are drawing in, numbered from plot number 1 in the upper left corner to plot number

You have probably already used subplot, but there are a few tricks to controlling the
size and appearance of the exported figure for publication. Here is an example of how to
produce a two -axis plot, formatted to t in a single column of a journal. Notice that in
such a figure, there are multiple sets of axes, so it is important to be clear which set you
are setting properties for . Figure 17.4 shows the plot produced by this script.

 Example 17.5a (ch17ex5a.m) % 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);

17.6 Making Raster Versions of Figures
While EPS figures are great for printing, the predominant method for presenting information
in a talk is with a computer projector, usually with something like PowerPoint.
Unfortunately, PowerPoint does a lousy job of rendering EPS les, so you may prefer to
make
a raster version of your figure to use in a presentation. In principle, you can just do
this by changing output resolution in the "Export Setup" dialog and then choosing a raster
format in the "Save as..." dialog. However, this can sometimes give mixed results.

We have found better results by exporting via the Matlab print command. (See Matlab
help for details on print.) To use this method, make sure to get a handle to the figure
window when it is created using the Figure 17.4 An example of a set of plots produced using subplot.
ff=figure

syntax. Then control the size and appearance as we discussed above for making EPS figures.
Then once your figure looks right, you can use the following code:
set (ff,'PaperUnits',Units,...
'PaperSize', [figWidth figHeight],...
'PaperPosition', [0 0 figWidth figHeight]);
print -djpeg -r600 'Test.jpg'

to make a jpeg image with good resolution (600 dpi). This code assumes you put the
size in the variables Units , figWidth, and figHeight as before. The raster images that
Matlab produces sometimes get rendering oddities in them, and they don't do anti-aliasing
to smooth the lines. This can sometimes be helped by increasing resolution or changing
what rendering method Matlab uses (see the Renderer property in "Figure Properties" in
Matlab help).

Another situation where raster graphics may be called for is for 3-D surface plots with
lighting, etc. These are hard to render in vector graphics formats, so even in when destined
for printing you may be better o making a raster figure le. Just control the resolution as
shown in the example code above to make sure your printed versions look OK. (We don't
recommend getting into the habit of doing this for print figures. Matlab's vector rendering
engines usually do a better job than its raster rendering engines.)

 Prev Next