1
votes

I want to create a contour plot in MATLAB, as in the second example on this page:

ContourPlot[Cos[x] + Cos[y] == 1/2, {x, 0, 4 Pi}, {y, 0, 4 Pi}]

As you can see, they are plotting only the lines for which f(X, Y) == some_value. Another issue I have is that I do not really have the function f, but only a collection of points of type [x, y, z] (read from a file), and some_value of course.

Is it possible to do such a plot in MATLAB?

2

2 Answers

1
votes

Simply use the contour function with a 2nd argument of desired values (it is a vector of 2 elements instead of a scalar, to distinguish the function call from another mode):

some_value = .5;
[x y] = meshgrid(linspace(0,4*pi,30),linspace(0,4*pi,30));
z = cos(x)+cos(y);
contour(x, y, z, [some_value, some_value])
0
votes

It helped me.

contourf(aX, aY, NM(:, :, k+1), 'ShowText','on', 'LevelStep', 0.4);