# I am trying to plot a contour graph with with x,y and z points

1 view (last 30 days)

Show older comments

##### 2 Comments

Adam Danz
on 25 Apr 2021

> How do I make z a 2x2 matrice

Impossible to answer without more info.

z(i,j) defines the z-value at x(i) and y(j).

### Answers (1)

Clayton Gotberg
on 26 Apr 2021

Edited: Clayton Gotberg
on 26 Apr 2021

It sounds like the problem is that you haven't made these functions into a grid.

You started with x and y, then found z as a function of x and y. However, I'd guess that when you did that, you just said z = f(x,y).

% What I think you have:

x = [1 2 3 4];

y = [4 3 2 1];

z = x+y; % This equals [5 5 5 5]

% This matches up each element in x with the element in the same location in y

%what I think you want:

z = x+y; % Except now it equals [5 6 7 8; 4 5 6 7; 3 4 5 6; 2 3 4 5].

% Now, every element in x is matched with every element in y.

% How to get what you want:

[X,Y] = meshgrid(x,y); % Now X = [1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4]

% and Y = [4 4 4 4; 3 3 3 3; 2 2 2 2; 1 1 1 1]

Z = X+Y;

##### 3 Comments

DGM
on 26 Apr 2021

### See Also

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!