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 view (last 30 days)
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

Accepted Answer

Shivam
Shivam on 11 Sep 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.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!