fplot
Plot
sin(x)
over the defaultx
interval[-5 5]
.
fplot(@(x) sin(x)) fig2plotly()
Plot the parametric curve x=cos(3t) and y=sin(2t).
xt = @(t) cos(3*t); yt = @(t) sin(2*t); fplot(xt,yt) fig2plotly()
Plot the piecewise function
None
Plot multiple lines using
hold on
. Specify the plotting intervals using the second input argument offplot
. Specify the color of the plotted lines as blue using'b'
. When you plot multiple lines in the same axes, the axis limits adjust to incorporate all the data.
fplot(@(x) exp(x),[-3 0],'b') hold on fplot(@(x) cos(x),[0 3],'b') hold off grid on fig2plotly()
Plot three sine waves with different phases. For the first, use a line width of 2 points. For the second, specify a dashed red line style with circle markers. For the third, specify a cyan, dash-dotted line style with asterisk markers.
fplot(@(x) sin(x+pi/5),'Linewidth',2); hold on fplot(@(x) sin(x-pi/5),'--or'); fplot(@(x) sin(x),'-.*c') hold off fig2plotly()
Plot
sin(x)
and assign the function line object to a variable.
fp = fplot(@(x) sin(x)) fig2plotly()
fig2plotly()fp = FunctionLine with properties: Function: @(x)sin(x) Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Show all properties
Change the line to a dotted red line by using dot notation to set properties. Add cross markers and set the marker color to blue.
fp.LineStyle = ':'; fp.Color = 'r'; fp.Marker = 'x'; fp.MarkerEdgeColor = 'b'; fig2plotly()
Plot two lines using
hold on
.
fplot(@(x) sin(x)) hold on fplot(@(x) cos(x)) hold off fig2plotly()
Plot sin(x) from -2π to 2π using a function handle. Display the grid lines. Then, add a title and label the x-axis and y-axis.
fplot(@sin,[-2*pi 2*pi]) grid on title('sin(x) from -2\pi to 2\pi') xlabel('x'); ylabel('y'); fig2plotly()
Use
gca
to access the current axes object. Display tick marks along the x-axis at intervals of π/2. Format the x-axis tick values by setting theXTick
andXTickLabel
properties of the axes object. Similar properties exist for the y-axis.
ax = gca; ax.XTick = -2*pi:pi/2:2*pi; ax.XTickLabel = {'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'};