MATLAB: Question about surf function

surf

t = linspace(0,2,100) x = linspace(0,10,100) [X,T]=meshgrid(x,t) U = 10*sin(2*pi*(t-x/5))+2*sin(2*pi*(t+x/5)) surf(X,T,U) Why it can not work? It always tips me Z must be a matrix.

Best Answer

t = linspace(0,2,100)
x = linspace(0,10,100)
[X,T]=meshgrid(x,t)
U = 10*sin(2*pi*(T-X/5))+2*sin(2*pi*(T+X/5))
surf(X,T,U)