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

조회 수: 2 (최근 30일)
Michelle Sy
Michelle Sy 2014년 3월 10일
댓글: Youssef Khmou 2014년 3월 10일
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)

답변 (1개)

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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by