0

How do you plot a user-defined function of two variables in Matlab?

1
  • 1
    you might find this plot gallery useful (click on any plot and you will see the code to produce it). In you case that would be a surface plot Commented Jul 27, 2012 at 0:57

3 Answers 3

1
X, Y = meshgrid(xs, ys); % values of x and y at which we want to evaluate
Z = my_func(X,Y);
surf(X,Y,Z);

Alternatively, if your function is not vectorized,

X, Y = meshgrid(xs, ys); % values of x and y at which we want to evaluate
for x = 1:length(xs)
  for y = 1:length(ys)
    Z(x,y) = my_func(X(x,y), Y(x,y));
  end
end
Z = my_func(X,Y);
surf(X,Y,Z);
Sign up to request clarification or add additional context in comments.

Comments

1

ezsurf is a simple solution, or ezmesh, or ezcontour, or ezsurfc, or ezmeshc.

Comments

0

It has many types.

You can go plot gallery and select your variable and then types like mesh, 3D, surface, ...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.