Azzera filtri
Azzera filtri

Plotting y=sin x in 3d

25 visualizzazioni (ultimi 30 giorni)
Amril Luqman
Amril Luqman il 8 Mag 2021
Commentato: Amril Luqman il 8 Mag 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)

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by