Cse1121 Lecture05
Cse1121 Lecture05
Scientific
Programming
Lecture 5: Plotting
• Two-Dimensional Plots
• Subplots
• Three Dimensional Plotng
•User Defined Functons
Histograms
• Useful for statstcal analysis
E > 0 to 60
D > 60 to 70
C > 70 to 80
B > 80 to 90
A > 90 to 100
>> bin_edge=[0,60,70,80,90,100.1]; >>
bar(bin_edge,n)
X-Y Graphs with Two Y Axes
• Sometmes it is useful to overlay two x-y plots onto
the same figure. However, if the order of
magnitude of the y values are quite different, it may
be difficult to see how the data behave.
For example
Scaling Depends on the
largest value plotted
• Its difficult to see how the blue line behaves, because the
scale isn’t appropriate
The plotyy
function allows
you to use two
scales on a
single graph
Different Types of Plots with two Y-axes
Adding Labels
Explore the
property editor to
see some of the
other ways you Change the
can adjust your Aspect Ratio
plot interactively Select Inspector
from the
Property Editor
• If you adjust a figure interactvely, you’ll lose your
improvements when you rerun your program
Interactive Plotting in MATLAB
5-42
The interactive plotting environment in MATLAB is
a set of tools for:
5-43
The Figure and Plot Edit toolbars displayed.
5-45
The Plot Tools interface includes the following
three panels associated with a given figure.
5-46
The Figure window with the Plot Tools
activated..
5-47
Saving your plots
• Rerun your M-file to recreate a plot
• Save the figure from the file menu using the save
as… opton
• You’ll be presented with several choices of file format
such as
• jpeg
• emg (enhanced metafile) etc
• Right-click on the figure and select copy - then
paste it into another document
• >> saveas(gcf,'myFigure.png')
• >>saveas(figure(2),'mfilename3.png')
Summary
• The x-y plot is the most common used in
engineering
•Graphs should always include ttles and axis labels.
Labels should include units.
•MATLAB includes extensive optons for controlling
the appearance of your plot
•Multple plots can be displayed in the same figure
window
•Most common plot types are supported by MATLAB
including
• polar plots
• bar graphs
• pie charts
• histograms
•MATLAB supports 3-D plotng
• line plots
• surface plots
• You can modify plots interactvely from the menu
bar
• You can create plots interactvely from the
workspace window
• Figures created in MATLAB can be stored using a
number of different file formats
User-Defined Functions
Objectives
This function
has two
inputs
A user defined function with
multiple inputs
Functions with Multiple
Outputs
• Recall the max
functon
• It returns two
results
T
At first this
function looks
like it returns
two values -
but it really
only returns a
single array
with two
elements
Functions with no input or no
output
• It isn’t always necessary to define an output
N
If star1 is set
equal to a
variable, the
rhyme is
returned