Contour plot using three vectors
229 views (last 30 days)
Hi. I want to make a contour plot using three vectors. The vectors "x" and "y" has the X and Y coordinates/positions. The vector "z" has numerical values of a property at corresponding (X,Y). All these vectors are of same size (1 X 50,000). I want to make a contour plot using three vectors. Can someone help me with it? I have tried contour and surf in vain and it didn't help.
Star Strider on 12 Nov 2019
I thought we already solved that in Contour plot of concentration of chemical species ?
Apparently I did not explain this step well enough:
xv = min(Freq(:,1)):max(Freq(:,1)); % ‘x’ Vector For Interpolation
yv = min(Freq(:,2)):max(Freq(:,2)); % ‘y’ Vector For Interpolation
[X,Y] = ndgrid(xv,yv); % Create Interpolation Grids
Z = griddata(Freq(:,1), Freq(:,2), Freq(:,3), X, Y); % Interpolated Grid Of ‘tally’ Values
The griddata function can interpolate vectors to matrices, here interpolating the three columns of the ‘Freq’ matrix (the three vectors you referred to), to the ‘X’ and ‘Y’ matrices that are created from them. Those matrices are created by ndgrid using the ‘xv’ and ‘yv’ vectors, that are intended to span the entire range of the first two columns of the ‘Freq’ matrix. It then creates the ‘Z’ matrix from them, by mapping the corresponding elements of ‘Freq(:,3)’ to the corresponding elements of ‘Z’.
Your ‘x’ and ‘y’ vectors apparently are not already gridded (they do not regularly repeat in particular patterns, although you did not share those data), so using reshape on them will not work correctly. You must instead interpolate them using griddata.
More Answers (1)
KSSV on 12 Nov 2019
It depends on how is your data. Is your data a structured data or a unstructured data? YOu have the following options. Let (x,y,z) be your three vectors.
xi = unique(x) ; yi = unique(y) ;
[X,Y] = meshgrid(xi,yi) ;
Z = reshape(z,size(X)) ;
dt = delaunayTriangulation(x,y) ;
tri = dt.ConnectivityList ;