MATLAB fplot3 in MATLAB®

Learn how to make 6 fplot3 charts in MATLAB, then publish them to the Web with Plotly.


Plot 3-D Parametric Line

Plot the 3-D parametric line

x=sin(t)
y=cos(t)
z=t

over the default parameter range [-5 5].

xt = @(t) sin(t);
yt = @(t) cos(t);
zt = @(t) t;
fplot3(xt,yt,zt)

fig2plotly()

Specify Parameter Range

Plot the parametric line

x=e-t/10sin(5t)
y=e-t/10cos(5t)
z=t

over the parameter range [-10 10] by specifying the fourth input argument of fplot3.

xt = @(t) exp(-t/10).*sin(5*t);
yt = @(t) exp(-t/10).*cos(5*t);
zt = @(t) t;
fplot3(xt,yt,zt,[-10 10])

fig2plotly()

Specify Line Properties and Display Markers

Plot the same 3-D parametric curve three times over different intervals of the parameter. For the first interval, 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.

fplot3(@(t)sin(t), @(t)cos(t), @(t)t, [0 2*pi], 'LineWidth', 2)
hold on
fplot3(@(t)sin(t), @(t)cos(t), @(t)t, [2*pi 4*pi], '--or')
fplot3(@(t)sin(t), @(t)cos(t), @(t)t, [4*pi 6*pi], '-.*c')
hold off

fig2plotly()

Plot Multiple Lines in Same Axes

Plot multiple lines in the same axes using hold on.

fplot3(@(t)t, @(t)t, @(t)t)
hold on
fplot3(@(t)-t, @(t)t, @(t)-t)
hold off

fig2plotly()

Modify 3-D Parametric Line After Creation

Plot the parametric line

x=e-|t|/10sin(5|t|)
y=e-|t|/10cos(5|t|)
z=t.

Assign the parameterized function line object to a variable.

xt = @(t)exp(-abs(t)/10).sin(5abs(t)); yt = @(t)exp(-abs(t)/10).cos(5abs(t)); zt = @(t)t; fp = fplot3(xt,yt,zt)

fp = 
  ParameterizedFunctionLine with properties:

    XFunction: @(t)exp(-abs(t)/10).*sin(5*abs(t))
    YFunction: @(t)exp(-abs(t)/10).*cos(5*abs(t))
    ZFunction: @(t)t
        Color: [0 0.4470 0.7410]
    LineStyle: '-'
    LineWidth: 0.5000

  Show all properties

Change the range of parameter values to `[-10 10]` and change the line color to red.
fp.TRange = [-10 10];
fp.Color = 'r';

fig2plotly()

Add Title and Axis Labels and Format Ticks

For t values in the range -2π to 2π, plot the parametric line

x=t y=t/2
z=sin(6t).

Add a title, x-axis label, and y-axis label. Additionally, change the view of the axes and display the axes box outline.

xt = @(t)t;
yt = @(t)t/2;
zt = @(t)sin(6*t);
fplot3(xt,yt,zt,[-2*pi 2*pi],'MeshDensity',30,'LineWidth',1);

title('x=t, y=t/2, z=sin(6t) for -2\pi'x');
ylabel('y');
view(52.5,30)
box on

fig2plotly()

Access the axes object using gca. Specify the x-axis tick values and associated labels using the XTick and XTickLabel properties of the axes object. Similarly, specify the y-axis tick values and associated labels.

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'};
ax.YTick = -pi:pi/2:pi;
ax.YTickLabel = {'-\pi','-\pi/2','0','\pi/2','\pi'};

fig2plotly()