Mathematical Expressions and Functions Plots in MATLAB®

How to make Mathematical Expressions and Functions Plots in MATLAB® with Plotly.


Plot Expression

Plot sin(x) over the default x interval [-5 5].

fplot(@(x) sin(x))

fig2plotly()

Plot Parametric Curve

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()

Specify Plotting Interval and Plot Piecewise Functions

Plot the piecewise function

ex   -3 < x < 0  
cos(x)  0 < x < 3.  

Plot multiple lines using hold on. Specify the plotting intervals using the second input argument of fplot. 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()

Specify Line Properties and Display Markers

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()