How to do surf plot if Z is not a matrix?

4 Ansichten (letzte 30 Tage)
Michelle Sy
Michelle Sy am 10 Mär. 2014
Kommentiert: Youssef Khmou am 10 Mär. 2014
I'm trying to make a 3-D surf plot but I'm not sure how I can acquire the Z value, because a is not defined and when I try to plug in numbers for a, and try to surf plot it, it says Z is not a matrix.
f(X,Y) = Z = 0.2 + sin(2*π*a*x)/(2*π*x) + sin(2*π*a*y)/(2*π*y)
HINT: Use the following code to set the range of x and y.
x=[-5:0.2:5]+eps; y=x; [X,Y]=meshgrid(x,y)
how can I make Z a matrix so I can use surf(X,Y,Z)

Antworten (1)

Marta Salas
Marta Salas am 10 Mär. 2014
Let's assume a is a number. There is a value of Z for every (X,Y), thus, Z is a matrix and it has same size as X.
a = 1;
x=[-5:0.2:5]+eps;
y=x;
[X,Y]=meshgrid(x,y)
Z = 0.2 + sin(2*pi*a*X)./(2*pi*X) + sin(2*pi*a*Y)./(2*pi*Y);
figure, surf(X,Y,Z)
  1 Kommentar
Youssef  Khmou
Youssef Khmou am 10 Mär. 2014
hi, i agree, this is an efficient way rather than using x,y loops .

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by