How to create 3D contour plot of a set of data consisting of series of points x,y,z with a quantity V(x,yz)?

1 visualización (últimos 30 días)
I have a set of data consisting of coordinates x,y,z and the value of a quantity V at each of these points.
like
x,y,z,V
1,3,5,9
3,5,7,-9
......
-4,6,2,1
I need to plot contours of V at the coordinates x,y,z. the number of different x values is NOT equal to the number of different y values.
Any help would be appriciated.
Thank you

Respuesta aceptada

Shivam
Shivam el 11 de Sept. de 2024
You can plot contours of V at the coordinates (x, y, z) by following the below mentioned workaround:
  1. Use scatteredInterpolant to interpolate the scattered data onto a regular grid.
  2. Then, plot the 3D contour slices of V using contourslice function.
% Sample data for demonstration
x = rand(20, 1) * 10;
y = rand(20, 1) * 10;
z = rand(20, 1) * 10;
V = sin(x) + cos(y) + z;
% Create a grid and interpolate
[xq, yq, zq] = meshgrid(linspace(min(x), max(x), 50), linspace(min(y), max(y), 50), linspace(min(z), max(z), 50));
F = scatteredInterpolant(x, y, z, V, 'linear', 'none');
Vq = F(xq, yq, zq);
% Plot 3D contours
figure;
contourslice(xq, yq, zq, Vq, [], [], linspace(min(z), max(z), 10));
xlabel('X');
ylabel('Y');
zlabel('Z');
title('3D Contour Plot of V');
colorbar;
grid on;
view(3);
For more info regarding the meshgrid, scatteredInterpolant and contourslice function, you can visit these official MATLAB documentations:
  1. https://www.mathworks.com/help/matlab/ref/meshgrid.html
  2. https://www.mathworks.com/help/matlab/ref/scatteredinterpolant.html
  3. https://www.mathworks.com/help/matlab/ref/contourslice.html
I hope this demonstration helps you with your data.
  1 comentario
NAFTALI HERSCOVICI
NAFTALI HERSCOVICI el 11 de Sept. de 2024
Thanks, your code works just fine as is. the issue is that size of X is NOT equal to the size of Y. I tried this case and the dode failed.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by