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

11 views (last 30 days)
Michelle Sy
Michelle Sy on 10 Mar 2014
Commented: Youssef Khmou on 10 Mar 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)

Answers (1)

Marta Salas
Marta Salas on 10 Mar 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 Comment
Youssef  Khmou
Youssef Khmou on 10 Mar 2014
hi, i agree, this is an efficient way rather than using x,y loops .

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!