Plot contours using discrete data points
67 views (last 30 days)
Hi. I have three matrices (X, Y & Z) with X & Y contains x, y coordinates and Z contains value at this location. I plotted a coloured plot using "scatter function" as shown below. But I want to plot the similar diagram as contour plot not like colouring discrete points based on values. Please help
Star Strider on 5 Jun 2021
‘Let say i have 100 points so my matrices(X,Y & Z) are 100 x1’
They could be gridded already. If they are, then simply using reshape the same way on eadh vector will create the necessary matrices. The easiest way to determine that is to plot them as:
stem3(X, Y, Z)
If they are gridded, the regularity will be immediately apparent.
Otherwise, do something like this —
xv = linspace(min(X), max(X));
yv = linspace(min(Y), max(Y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(X, Y, Z, Xm, Ym);
contourf(Xm, Ym, Zm)
Providing that there are no serious prolbmes with the origina vectors, that should work.