Plotting y=sin x in 3d

56 次查看(过去 30 天)
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)

采纳的回答

DGM
DGM 2021-5-8
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 个评论
Amril Luqman
Amril Luqman 2021-5-8
Ohh.. i want the graph to looks like the second one. Thank you very much for the help!!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by