"Chris " <cstanislawczyk@gmail.com> wrote in message <ian8qk$crn$1@fred.mathworks.com>...
> Hello,
> I am working on a project where, in the end, I will have a 3D animation of a time resolved process that will involve a changing 3D surface plot. Currently I am having a little bit of trouble with the limiting my plotting. I have used MatLab before and although I do not classify myself as a beginner, an am still not that experienced.
>
> So basically what I am stuck on is this: I want to have a user input for a surface geometry, lets say z=(x^2)(y^2) and I want a surface plot of that,but I only want displayed the portion of that function that within a circular region of radius r. It seems that what ever I try I can not get MatLab to display anything other then the full region of the plot axis.
>
> How would I go about limiting the plot? Would I have to write a code that sets anything outside of that region to NaN because that is the only thing I can think of and if that is the easiest how would I code something like that? Thank you in advance.
% Another way is to work in polar coordinates and use meshgrid.
% In your case, something like:
theta = linspace(0,2*pi,25);
r = linspace(0,5,25);
[TH,R] = meshgrid(theta,r);
Z=((R.*cos(TH)).^2)((R.*sin(TH)).^2); % z=(x^2)(y^2)
[x,y,z] = pol2cart(TH,R,Z);
surf(x,y,z)
