Contour Plots from column vector

Hi,
I am trying to obtain a filled contour plot from three column vectors. The first vector is the x-coordinate, the second vector is the y-coordinate and the third vector is the temperature at corresponding x,y location. The three column vector data have been exported from a simulation result. I have attached the text file here.
Image 1 shows the scatter plot of the x-y coordinates.
I tried the following piece of code and the resulting contour plot looks something like this (Image 2).
[xq,yq] = meshgrid(x,y); % x = first column, y = second column
[X1,Y1,Z1] = griddata(x,y,z,xq,yq); % z = third column
contourf(X1,Y1,Z1,200,'LineStyle','none')
I used the contour plot from a third party software and the correct resulting plot is image 3. I am trying the get the same result using Matlab.
Can someone please help me with this?
Thank you!

Antworten (1)

Star Strider
Star Strider am 8 Dez. 2021

0 Stimmen

Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/827635/Temperature%20data.txt', 'VariableNamingRule','preserve')
T1 = 1873×3 table
Var1 Var2 Var3 _________ __________ ______ 0.0099362 0.00044647 2.2511 0.0099362 0.00056765 2.1114 0.0098083 0.00044647 2.1227 0.0098083 0.00056765 2.0295 0.0096809 0.00044647 2.0236 0.0096809 0.00056765 1.9602 0.0095536 0.00044647 1.9418 0.0095536 0.00056765 1.8966 0.0094258 0.00044647 1.8734 0.0094258 0.00056765 1.8412 0.0092983 0.00044647 1.8159 0.0092983 0.00056765 1.7929 0.0091582 0.00044647 1.7629 0.0091582 0.00056765 1.7472 0.0090055 0.00044647 1.7149 0.0090055 0.00056765 1.7049
xv = linspace(min(T1.Var1), max(T1.Var1), numel(T1.Var1));
yv = linspace(min(T1.Var2), max(T1.Var2), numel(T1.Var2));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(T1.Var1, T1.Var2, T1.Var3, Xm, Ym);
figure
contourf(Xm, Ym, Zm, 15, 'ShowText','on')
figure
surfc(Xm, Ym, Zm, 'EdgeColor','none')
grid on
view(150,30)
.

Kategorien

Mehr zu Contour Plots finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2021b

Gefragt:

am 8 Dez. 2021

Beantwortet:

am 8 Dez. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by