Plotting y=sin x in 3d

46 views (last 30 days)
Amril Luqman
Amril Luqman on 8 May 2021
Commented: Amril Luqman on 8 May 2021
I want to plot y=sin x,0≤ x ≤ 2π, with 300 linear space points interval in 3D. Im kinda new to matlab, so i the read help center to learn how to do plot 3d graph. Can someone help me check it if it correct or not?
x=linspace(0,2*pi,300);
[x,y]=mehsgrid(x);
z=sin(x);
surf(x,y,z)

Accepted Answer

DGM
DGM on 8 May 2021
What did you get when you ran it? Whether it's "right" depends on what the goal is.
% this plots the surface over both x and y
% z is invariant over y
x = linspace(0,2*pi,300);
[x,y]=meshgrid(x); % spelled right
z = sin(x);
surf(x,y,z)
% this plots z for y=0
x = linspace(0,2*pi,300);
y = zeros(size(x));
z = sin(x);
plot3(x,y,z)
Depends what you want.
  1 Comment
Amril Luqman
Amril Luqman on 8 May 2021
Ohh.. i want the graph to looks like the second one. Thank you very much for the help!!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!