MESHGRID and Contour

Hello,
I have 3 vectors x,y,z; with x and y representing co-ordinates and z their values, which are temperatures assigned to the 13 points. Basically what i want to do is create a sort of 'heatmap' that will display temperatures on a 2 dimensional plot that corresponds to the correct x and y coordinates. Here is what I did and where I got stuck:
[x1,y1] = meshgrid(x,y)
Now the problem is how do i get the z into a correct 13*13 matrix to use contour(x1,y1,z)?
Any help would be appreciated.
J

 Respuesta aceptada

Walter Roberson
Walter Roberson el 24 de Abr. de 2012

0 votos

Do you have a z for each x / y combination? e.g., z(2,3) = f(x(2), y(3)) ? Or do you have only a vector in which x(1) relates only to y(1) and z(1), x(2) only to y(2) and z(2), etc. (scattered values)?
If you have only scattered values, and you have a sufficiently new MATLAB version, see http://www.mathworks.com/help/techdoc/ref/triscatteredinterp.html

6 comentarios

J
J el 24 de Abr. de 2012
My data creates a 4*4 grid when it is on a 2-d x,y plot
Here is my data (i am using log scales):
X Y Intensity
0.000000187 0.000000111 84.50318071
0.000000187 1.11E-08 17.93305682
0.000000187 1.11E-09 12.03762387
0.000000187 0.00000111 10.50386162
1.87E-08 0.000000111 83.57328642
1.87E-08 0.00000111 9.9743495
1.87E-09 0.000000111 75.01349657
1.87E-09 1.11E-08 103.5619297
1.87E-09 0.00000111 6.666592105
1.87E-10 0.000000111 42.93567326
1.87E-10 1.11E-08 64.46820503
1.87E-10 1.11E-09 66.86520097
1.87E-10 0.00000111 1.607438028
J
J el 24 de Abr. de 2012
im sorry for the bad spacing, i copied it from excel
Basically, i have 4 different x's and four different y's and values for each combo
J
J el 24 de Abr. de 2012
also i have versions R2007a and R2011a available
Walter Roberson
Walter Roberson el 24 de Abr. de 2012
You only appear to have 13 values to put into 16 matrix locations ? What do you want to have happen for the places where the data is missing? Should NaN be put there? Did you want interpolation to fill in the NaN as a step after that and before drawing the image?
J
J el 24 de Abr. de 2012
This helped me figure it out, i was repeating X points
Walter Roberson
Walter Roberson el 24 de Abr. de 2012
If you had all of the data pairs, in a regular order, then the matrix could be filled in by taking the z vector, reshaping it, and transposing the result, with the corresponding x and y value orders extracted from the vectors. You might also need to do a flip of the matrix as your x appears to be in decreasing order.
Another approach that would work even with incomplete values would be:
[xu, xjunk, xidx] = unique(x);
[yu, yjunk, yidx] = unique(y);
ValMatrix = accumarray([xidx(:), yidx(:)], [], [], NaN);
IValMatrix = inpaint_nans(ValMatrix);
contour(xu, yu, IValMatrix);
In the above, inpaint_nans is the MATLAB File Exchange contribution of that name, written by John D'Errico.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Contour Plots en Centro de ayuda y File Exchange.

Productos

Preguntada:

J
J
el 24 de Abr. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by