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 (최근 30일)
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

채택된 답변

Shivam
Shivam 2024년 9월 11일
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
NAFTALI HERSCOVICI
NAFTALI HERSCOVICI 2024년 9월 11일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by