Plot contours using discrete data points

53 visualizaciones (últimos 30 días)
mukesh bisht el 5 de Jun. de 2021
Comentada: Star Strider el 6 de Jun. de 2021
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
0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Respuestas (2)

SALAH ALRABEEI el 5 de Jun. de 2021
% try this
contour(X,Y,Z)
or
% this
contourf(X,Y,Z)
3 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
SALAH ALRABEEI el 5 de Jun. de 2021
what is ur Z!! is it a function!!
mukesh bisht el 5 de Jun. de 2021
No it is not a function. Corresponding to each point P(x,y), matrix Z contain a single discrete value

Iniciar sesión para comentar.

Star Strider el 5 de Jun. de 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:
figure
stem3(X, Y, Z)
grid on
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);
figure
contourf(Xm, Ym, Zm)
axis('equal')
Providing that there are no serious prolbmes with the origina vectors, that should work.
.
4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
mukesh bisht el 6 de Jun. de 2021
I have attached the data (X,Y,Z) matrix.
Star Strider el 6 de Jun. de 2021
Having the data to experiment with made all the difference!
To make the contourf plot appear smoother, increase the number of contours. (I increased them to 200 here. Increase them further as desired.) The ‘steps’ are still there, there are simply more of them.
X = T1{:,1};
Y = T1{:,2};
Z = T1{:,3};
xv = linspace(min(X), max(X));
yv = linspace(min(Y), max(Y));
[Xm,Ym] = ndgrid(xv, yv);
Zm = griddata(X, Y, Z, Xm, Ym);
figure
contourf(Xm, Ym, Zm, 200, 'LineStyle','none')
colormap(turbo)
colorbar
axis('equal')
Rotating it and putting it in the circle would be possible, however I would need to know how you arrived at that.
.

Iniciar sesión para comentar.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by