Plotting contours of Z on an x-y axis where Z is not a function of x or y

조회 수: 20 (최근 30일)
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?

채택된 답변

Aquatris
Aquatris 2019년 1월 4일
편집: Aquatris 2019년 1월 7일
You do not have a lot of data so the countour map will not look great. However what you need to do is;
% create data
x = [0.2 2 7 7];
y = [9.4 9.3 5 5];
z = [17 17.85 17.65 17.5];
% create xy axis grid
[X,Y] = meshgrid(x,y);
% create corresponding Z values, assume z = 0 for locations with no z data
Z = zeros(length(x),length(y)) ;
for i = 1:length(x)
for j = 1:length(y)
if i==j % z data exist for only for x(n) y(n) location, n = 1,2,3...
Z(i,j) = z(i);
end
end
end
contourf(X,Y,Z)
  댓글 수: 2
JS
JS 2019년 1월 5일
Thank you for this! This produces the kind of contour map that I want.
Saurabh Das
Saurabh Das 2020년 7월 2일
Thanks very much. This was quite helpful!

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2020년 7월 2일
You should probably be using scatteredInterpolant() or griddedInterpolant().
  댓글 수: 3
Walter Roberson
Walter Roberson 2020년 7월 2일
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.

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


Vidya shree V
Vidya shree V 2020년 9월 24일
I have R Z T value how to plot contour graph in matlab
  댓글 수: 4
Rita Douaihy
Rita Douaihy 2021년 10월 25일
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
Walter Roberson
Walter Roberson 2021년 10월 25일
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');

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

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by