Plot 3D of a function
2 次查看(过去 30 天)
显示 更早的评论
Hello is there a short cut to plot a 3d function for example i have a linspace(0,pi) of x and linspace(0,1) of t and the a function @(x,t)=f(x,t). The way i have plotted is having x and t and loop for which calculates the values of x and t evaluated in the function:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/524884/image.png)
In the image above i have created a vectors x1 and t1 of lenght=300 and evaluate them in the funcion
and store them in the matrix z1. I have tried this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/524889/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/524894/image.png)
But i dont think is the best way cause it takes a lot. Any suggestion.
采纳的回答
Alan Stevens
2021-2-19
Are you looking for something like this?
x = linspace(0,pi);
t = linspace(0,1);
z = @(x,t) 10*exp(-4*t).*sin(2*x);
[x1, t1] = meshgrid(x,t);
z1 = z(x1,t1);
surf(x1,t1,z1)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!