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

 채택된 답변

Walter Roberson
Walter Roberson 2012년 4월 24일

0 개 추천

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

J
J 2012년 4월 24일
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 2012년 4월 24일
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 2012년 4월 24일
also i have versions R2007a and R2011a available
Walter Roberson
Walter Roberson 2012년 4월 24일
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 2012년 4월 24일
This helped me figure it out, i was repeating X points
Walter Roberson
Walter Roberson 2012년 4월 24일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Contour Plots에 대해 자세히 알아보기

제품

질문:

J
J
2012년 4월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by