Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contour plot with 3 vector

I've a matrix M 10201x3 where the first 2 column are constant used to compute the response Z in column 3. Example:

....    ...     .................
0.0031  0.02    0.792729854583740
0.0031  0.03    0.802729845046997
0.0031  0.04    0.812729895114899
0.0031  0.05    0.822729885578156
....    ...     .................
0.0034  0.02    0.867461800575256
0.0034  0.03    0.877461791038513
0.0034  0.04    0.887461841106415
0.0034  0.05    0.897461831569672
0.0034  0.06    0.907461822032929
....    ...     .................

I wanna make a contour plot where X = M(:,1), Y = M(:,2) and Z = M(:,3) with different colors for different hights. I need to do the same thing in both 2D and 3D.

like image 354
gmeroni Avatar asked Jul 03 '26 08:07

gmeroni


1 Answers

I assume your data is regular, and you know how many repeating x-elements you have. Let's call the number of repeating x = L - or you'll be able to find that out.

You need to reshape your vectors:

X = reshape(X,[],L);
Y = reshape(Y,[],L);
Z = reshape(Z,[],L);

You need Z how it is, but just the first row of X and the first column of Y.

X = X(:,1);
Y = Y(1,:);

and then you can use contour:

contour(X,Y,Z); 

There is no need for interpolation!

contour(X,Y,Z), contour(X,Y,Z,n), and contour(X,Y,Z,v) draw contour plots of Z using X and Y to determine the x- and y-axis limits.

If X and Y are vectors, then the length of X must equal the number of columns in Z and the length of Y must equal the number of rows in Z.

If X and Y are matrices, then their sizes must equal the size of Z.

Therefore shorter:

X = X(1:L:end);
Y = Y(1:L);
Z = reshape(Z,[],L);

contour(X,Y,Z); 
like image 122
Robert Seifert Avatar answered Jul 05 '26 16:07

Robert Seifert



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!