0

I want to display the values of a function Z = Z(x,y) in the range (x_min, x_max) and (y_min, y_max) using the contourf function in Matlab 2015a. Here is my code:

N = 20;
x_min = 20;
x_max = 40;
y_min = 40;
y_max = 80;
x = linspace(x_min, x_max, N);
y = linspace(y_min, y_max, N);
[X,Y] = meshgrid(y,x);
Z = X.*Y;
for i = 1:N
    for j = 1:N
        Z(i, j) = 10*i+j;
    end
end
contourf(Z);
colorbar

And this is the plot I get: enter image description here

How can I show the true range of x and y (20<=x=<40 and 40<=y=<80)?

dasdingonesin
  • 1,347
  • 1
  • 10
  • 16
user2738748
  • 1,106
  • 2
  • 19
  • 36

1 Answers1

4

A look at the fantastic MATLAB documentation reveals that you can supply three arguments to contourf, namely the X, Y, and Z values.

N = 20;
x_min = 20;
x_max = 40;
y_min = 40;
y_max = 80;
x = linspace(x_min, x_max, N);
y = linspace(y_min, y_max, N);
[X,Y] = meshgrid(y,x);
Z = X.*Y;
for i = 1:N
    for j = 1:N
        Z(i, j) = 10*i+j;
    end
end
contourf(X,Y,Z);
colorbar

This will give you properly labelled tick marks:

contourf

dasdingonesin
  • 1,347
  • 1
  • 10
  • 16