Plotting contours of Z on an x-y axis where Z is not a function of x or y
Show older comments
Hello,
I have collected data of temperature measurements at certain coordinates in a room. I want to plot these temperature measurements on a contour map, where the X and Y axis are the perimeter (and dimensions) of the room, and the contours of Z are the temperature measurements I have taken. The total size of the room is x=7m, and y=10.6m. I cannot find a way of plotting a contour map where Z is not a function of x or y. The measurements of temperature (Z) at certain x- and y-coordinates in the room are shown below:
Coordinates Temperature
X Y Z
0.2 9.4 17.0
2 9.3 17.85
7 5 17.65
7 5 17.5
Is there a way of plotting this on a 2D contour map, where the values of Z are shown on the contours?
Accepted Answer
More Answers (2)
Walter Roberson
on 2 Jul 2020
1 vote
You should probably be using scatteredInterpolant() or griddedInterpolant().
3 Comments
Saurabh Das
on 2 Jul 2020
Hi Walter,
Though the method shown by Aquatris helped me to get a shade of the graph that I am looking for, all the other elements about the diagonal are zero in the Z matrix of contour(X,Y,Z) as per the abovementioned fix.
My script is such that I cannot express Z as a function of X and Y. So, the error message shown below pops up
"Z must be atleast of dimensions 2x2."
Is there any other way to obtain a contour plot if my X, Y and Z matrices are of dimensions 1x850 after all the calculations are completed?
I have been using meshgrid and the method proposed by Aquatris but am not at all satisfied with the results. But, the good news is that I am atleast getting a plot.
Any help would be greatly appreciated!
Walter Roberson
on 2 Jul 2020
x = [0.2 2 7 7];
y = [9.4 9.3 5 5];
z = [17 17.85 17.65 17.5];
N = 100;
xvec = linspace(min(x), max(x), N);
yvec = linspace(min(y), max(y), N);
F = scatteredInterpolant(x(:), y(:), z(:));
[X, Y] = ndgrid(xvec, yvec);
Z = F(X, Y);
surf(X, Y, Z, 'edgecolor', 'none');
Note that your last two X, Y coordinates are the same but different Z: the data will be averaged.
You effectively only have three different points with this data, so the output is a plane.
Saurabh Das
on 30 Sep 2020
Thanks very much. It was helpful!
Vidya shree V
on 24 Sep 2020
0 votes
I have R Z T value how to plot contour graph in matlab
4 Comments
Walter Roberson
on 24 Sep 2020
How do the values relate to each other? Are they vectors or grids? Are two of them "marginal vectors" and the other one effectively a grid?
ASHUTOSH KUMAR SINGH
on 1 Oct 2020
Hello Walter, I have a data consisting of a X,Y coordinate and values of force data which I want to be on Z.I want to plot a 3d plot (a surface plot)
But the X, Y are Z data are not equal and almost no relation between the (X,Y) and Z. I have attached the excel sheet. Thank you in advance.

Rita Douaihy
on 25 Oct 2021
Hello did you find an answer to your question ? The above script did not work for me and I have similar case were X,Y and Z values are data in an excel sheet and not related
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/369253/plotSecond.xlsx';
T = readmatrix(filename);
X = T(2:end,1);
Y = T(1,2:end);
Z = T(2:end,2:end).'; %notice the transpose
surf(X, Y, Z, 'edgecolor', 'none');
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!