phdstudent
phdstudent

Reputation: 1144

Three dimensional plot on matlab

I am trying to do a figure similar to the one attached.

I have exactly a (224x1) vector with dates (x-axis), a (10x1) vector with maturities (y-axis) and a (224x10) matrix with the values (z-axis).

I tried surf(X, Y, Z) but I got an error ("data dimensions must agree").

How can I combine this to make a plot like the one attached?

Thanks, V!

Edit: The second plot is the one I am getting using Luis Mendo's suggestion:

3d plot

enter image description here

Upvotes: 2

Views: 927

Answers (2)

Luis Mendo
Luis Mendo

Reputation: 112769

Use

surf(Y,X,Z)

From the documentation (emphasis added):

surf(x,y,Z) and surf(x,y,Z,C), with two vector arguments replacing the first two matrix arguments, must have length(x) = nand length(y) = m where [m,n] = size(Z). In this case, the vertices of the surface patches are the triples (x(j), y(i), Z(i,j)). Note that x corresponds to the columns of Z and y corresponds to the rows.

Upvotes: 2

Ander Biguri
Ander Biguri

Reputation: 35525

Do

[X,Y]=meshgrid(x,y);
surf(X,Y,Z);

You need to create a meshgrid to be able to plot a surf. X ,Y and Z need to be the same size!

Upvotes: 1

Related Questions