I want to create a contour plot,like above, of a plate with temperatures at specific points on the plate. The data should be interpolated bicubical. Now i have just a few points on my plate but wanted the contour and so the interpolated data over the full size of the plate is this possible?
Below you can find some example data with x- and y-coordinates and also some temperatures corresponding to the coordinates.
X_Plate=200; % length mm
Y_Plate=400; % heigth mm
x=[-80 -50 0 50 60]; % x-coordinates
y=[-150 -100 0 100 130]; % y-coordinates
T=[15 20 30 10 5]; % Temperature °C
% the coordinate system has its origin in the center of the plate
I would be very pleased if someone could help me.

 채택된 답변

Cris LaPierre
Cris LaPierre 2020년 10월 30일
편집: Cris LaPierre 2020년 10월 30일

0 개 추천

In order to create a contour plot, you will need to have a temperature measurement for each (x,y) permutation. This means T needs to be a matrix with the same number of rows as there are values in y, and the same number of columns as there are values in x. The column and row indices of T are the x and y coordinates in the plane, respectively.
x=[-80 -50 0 50 60]; % x-coordinates
y=[-150 -100 0 100 130]; % y-coordinates
T=[15 20 30 10 5]; % Temperature °C
z=ones(5,1)*T
z = 5×5
15 20 30 10 5 15 20 30 10 5 15 20 30 10 5 15 20 30 10 5 15 20 30 10 5
contourf(x,y,z)

댓글 수: 5

Perhaps your intent was something like this?
x=[-80 -50 0 50 60]; % x-coordinates
y=[-150 -100 0 100 130]; % y-coordinates
T=[15 20 30 10 5]; % Temperature °C
z=zeros(length(y),length(x));
z([1,7,13,19,25]) = T
z = 5×5
15 0 0 0 0 0 20 0 0 0 0 0 30 0 0 0 0 0 10 0 0 0 0 0 5
contourf(x,y,z)
colorbar
Bavi John
Bavi John 2020년 10월 30일
Yes, this is what I intended. Thanks a lot for your reply. Now i just have to interpolate my data and fill the matrix z diagonally. I think I'll figure this out myself.
Cris LaPierre
Cris LaPierre 2020년 10월 30일
Sure. I'm taking advantage of linear indexing. You might find the sub2ind function helpful for this.
Is it also possible with coordinates like below?
The contour plot can't deal with vectors, if they don't strictly increasing.
x=[0 0 -80 30 60]; % x-coordinates
y=[0 140 0 50 -10]; % y-coordinates
Error using contourf (line 57)
Vector X must be strictly increasing or strictly decreasing with no repeated values.
You would apply the principle, rather than the implementation. Here, you need to define x and y as matrices I think.Then, using the same T values as before, create z using the linear indexing of the (x,y) coordinates.
x=[-80 0 30 60]; % x-coordinates
y=[-10 0 50 140];
[X,Y] = meshgrid(x,y)
X = 4×4
-80 0 30 60 -80 0 30 60 -80 0 30 60 -80 0 30 60
Y = 4×4
-10 -10 -10 -10 0 0 0 0 50 50 50 50 140 140 140 140
T=[15 20 30 10 5]; % Temperature °C
z=zeros(length(y),length(x));
% Create linear index of the desired x and y value pairs
lind = sub2ind([4,4],[2 4 2 3 1],[2 2 1 3 4]);
z(lind) = T
z = 4×4
0 0 0 5 30 15 0 0 0 0 10 0 0 20 0 0
contourf(X,Y,z)
colorbar

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

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 30일
편집: Ameer Hamza 2020년 10월 30일

3 개 추천

You first need to use scatteredInterpolant to convert the data to a grid format and then call contourf(). Since you have very few data points, so the variation will also be small
x=[-80 -50 0 50 60]; % x-coordinates
y=[-150 -100 0 100 130]; % y-coordinates
T=[15 20 30 10 5]; % Temperature °C
% the coordinate system has its origin in the center of the plate
mdl = scatteredInterpolant(x(:), y(:), T(:), 'natural');
xg = linspace(min(x), max(x), 20);
yg = linspace(min(x), max(x), 20);
[Xg, Yg] = meshgrid(xg, yg);
Zg = mdl(Xg, Yg);
contourf(Xg, Yg, Zg, 10);

댓글 수: 1

Bavi John
Bavi John 2020년 10월 30일
Thanks for your suggestion. Didn't know this scatteredInterpolant, It will be very useful I think.

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

카테고리

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

질문:

2020년 10월 30일

편집:

2020년 10월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by