Contour Plots from column vector
Ältere Kommentare anzeigen
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)
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/827635/Temperature%20data.txt', 'VariableNamingRule','preserve')
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
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

