create 2-d graph and customize lines - matlab & simulink - mathworks deutschland

8
&UHDWH ' *UDSK DQG &XVWRPL]H /LQHV 0$7/$% 6LPXOLQN 0DWK:RUNV 'HXWVFKODQG KWWSGHPDWKZRUNVFRPKHOSPDWODEFUHDWLQJBSORWVXVLQJKLJKOHYHOSORWWLQJIXQFWLRQVKWPO 2SHQ 7KLV ([DPSOH 2SHQ 7KLV ([DPSOH &UHDWH ' *UDSK DQG &XVWRPL]H /LQHV &UHDWH ' /LQH *UDSK 7KLV H[DPSOH VKRZV KRZ WR FUHDWH D VLPSOH OLQH JUDSK 8VH WKH IXQFWLRQ WR GHILQH DV D YHFWRU RI OLQHDUO\ VSDFHG YDOXHV EHWZHHQ DQG ʰ ſɥřɩƋřɨɥɥƀŚ 'HILQH DV WKH VLQH IXQFWLRQ HYDOXDWHG DW WKH YDOXHV LQ ʰ ſƀŚ 3ORW YHUVXV WKH FRUUHVSRQGLQJ YDOXHV LQ ſřƀ &UHDWH *UDSK LQ 1HZ )LJXUH :LQGRZ 7KLV H[DPSOH VKRZV KRZ WR FUHDWH D JUDSK LQ D QHZ ILJXUH ZLQGRZ LQVWHDG RI SORWWLQJ LQWR WKH FXUUHQW ILJXUH 'HILQH DQG ʰ ſɥřɩƋřɩɬƀŚ ʰ ſƀŚ &UHDWH D VWDLUVWHS SORW RI YHUVXV 2SHQ D QHZ ILJXUH ZLQGRZ XVLQJ WKH FRPPDQG ,I \RX GR QRW RSHQ D QHZ ILJXUH ZLQGRZ WKHQ E\ GHIDXOW 0$7/$% FOHDUV H[LVWLQJ JUDSKV DQG SORWV LQWR WKH FXUUHQW ILJXUH

Upload: david-ahoua

Post on 11-Jul-2016

212 views

Category:

Documents


0 download

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,'*')