create 2-d graph and customize lines - matlab & simulink - mathworks deutschland
TRANSCRIPT
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 1/8
Open This Example
Open This Example
Create 2-D Graph and Customize Lines
Create 2-D Line GraphThis example shows how to create a simple line graph. Use the linspace function todefine x as a vector of 100 linearly spaced values between 0 and .
x = linspace(0,2*pi,100);
Define y as the sine function evaluated at the values in x.
y = sin(x);
Plot y versus the corresponding values in x.
figure plot(x,y)
Create Graph in New Figure WindowThis example shows how to create a graph in a new figure window, instead of plottinginto the current figure.
Define x and y.
x = linspace(0,2*pi,25); y = sin(x);
Create a stairstep plot of y versus x. Open a new figure window using the figure command. If you do not opena new figure window, then by default, MATLAB® clears existing graphs and plots into the current figure.
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 2/8
Open This Example
figure % new figure window stairs(x,y)
Plot Multiple LinesThis example shows how to plot more than one line by passing multiple x,y pairs to theplot function.
Define y1 and y2 as sine waves with a phase shift.
x = linspace(0,2*pi,100); y1 = sin(x); y2 = sin(x-pi/4);
Plot the lines.
figure plot(x,y1,x,y2)
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 3/8
Open This Example
plot cycles through a predefined list of line colors.
Colors, Line Styles, and MarkersTo change the line color, line style, and marker type, add a line specification string to the x,y pair. For example,adding the string, 'g:*', plots a green dotted line with star markers. You can omit one or more options from theline specification, such as 'g:' for a green dotted line with no markers. To change just the line style, specifyonly a line style option, such as '--' for a dashed line.
For more information, see the LineSpec input argument for plot.
Specify Line StyleThis example shows how to create a plot using a dashed line. Add the optional linespecification string, '--', to the x,y pair.
x = linspace(0,2*pi,100); y = sin(x);
figure plot(x,y,'--')
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 4/8
Open This Example
Specify Different Line Styles for Multiple LinesThis example shows how to plot two sine waves with different line styles by adding a linespecification string to each x,y pair.
Plot the first sine wave with a dashed line using '--'. Plot the second sine wave with a dotted line using ':'.
x = linspace(0,2*pi,100); y1 = sin(x); y2 = sin(x-pi/4);
figure plot(x,y1,'--',x,y2,':')
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 5/8
Open This Example
Specify Line Style and ColorThis example shows how to specify the line styles and line colors for a plot.
Plot a sine wave with a green dashed line using '--g'. Plot a second sine wave with ared dotted line using ':r'. The elements of the line specification strings can appear in any order.
x = linspace(0,2*pi,100); y1 = sin(x); y2 = sin(x-pi/4);
figure plot(x,y1,'--g',x,y2,':r')
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 6/8
Open This Example
Specify Line Style, Color, and MarkersThis example shows how to specify the line style, color, and markers for two sine waves.If you specify a marker type, then plot adds a marker to each data point.
Define x as 25 linearly spaced values between 0 and . Plot the first sine wave with a green dashed line andcircle markers using '--go'. Plot the second sine wave with a red dotted line and star markers using ':r*'.
x = linspace(0,2*pi,25); y1 = sin(x); y2 = sin(x-pi/4);
figure plot(x,y1,'--go',x,y2,':r*')
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 7/8
Open This Example
Plot Only Data PointsThis example shows how to plot only the data points by omitting the line style option fromthe line specification string.
Define the data x and y. Plot the data and display a star marker at each data point.
x = linspace(0,2*pi,25); y = sin(x);
figure plot(x,y,'*')
17.3.2016 Create 2-D Graph and Customize Lines - MATLAB & Simulink - MathWorks Deutschland
http://de.mathworks.com/help/matlab/creating_plots/using-high-level-plotting-functions.html 8/8
•••
See Alsocontour | linspace | loglog | plot | plotyy | scatter | semilogx | semilogy | stairs | stem
Related ExamplesAdd Title, Axis Labels, and Legend to GraphChange Axis Limits of GraphChange Axis Tick Values and Labels