Geoscience Reference
In-Depth Information
function createfigure(X1, Y1)
%CREATEFIGURE(X1, Y1)
% X1: vector of x data
% Y1: vector of y data
% Auto-generated by MATLAB on 27-Jun-2014 13:28:13
% Create figure
figure1 = figure('Color',[0.68 0.92 1]);
% Create axes
axes1 = axes('Parent',figure1,'ColorOrderIndex',2);
box(axes1,'on');
hold(axes1,'on');
% Create plot
plot(X1,Y1,'MarkerSize',15,'Marker','square','LineWidth',2);
We can then rename the function createfigure to mygraph and save the i le
as mygraph.m .
function mygraph(X1, Y1)
%MYGRAPH(X1,Y1)
% X1: vector of x data
% Y1: vector of y data
(cont'd)
h e automatically-generated graphics function illustrates how graphics are
organized in MATLAB. h e function figure i rst opens a Figure Window.
Using axes then establishes a coordinate system, and using plot draws the
actual line object. h e Figure section in the function reminds us that the
light-blue background color of the Figure Window is represented by the
RGB color coding [0.68 0.92 1] . h e Plot section reveals the square marker
symbol used and the line width of 2 points.
h e newly-created function mygraph can now be used to plot a dif erent
data set. We use the above example and
clear
x = 0 : pi/10 : 2*pi;
y2 = cos(x);
mygraph(x,y2)
h e i gure shows a new plot with the same layout as the previous plot.
h e Generate Code function of MATLAB can therefore be used to create
templates for graphics that can be used to generate plots of multiple data sets
using the same layout.
Even though MATLAB provides abundant editing facilities and the
Generate Code function even allows the generation of complex templates
Movie
2.5
Search WWH ::




Custom Search