How to use plot3 restrict to a certain region in Matlab?
matlab, wolfram-mathematica
Solution
Here's a not particularly elegant solution that sets the function values of the region you don't want to see to -infinity.
[x, y] = meshgrid(-4:0.1:4, -4:0.1:4);
z = sin(x.^2+y.^2)./(x.^2+y.^2);
idx = x.^2 + y.^2 > 4*pi;
z(idx) = -Inf;
surf(x, y, z); axis vis3d;
Edit. Actually, if you try a finer grid (say -4:0.01:4) and add `shading interp` it doesn't look too bad.
Problem
For example, I want to plot the function ``` f(x,y) =sin(x^2+y^2)/(x^2+y^2), x^2+y^2 <=4π ``` In Mathematica, I can do it as following: ``` Plot3D[Sin[x^2 + y^2]/(x^2 + y^2), {x, -4, 4}, {y, -4, 4}, RegionFunction -> (#1^2 + #2^2 <= 4 Pi &)] ``` Where the `RegionFunction` specified the region of x,y to plot.