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)?

2 ビュー (過去 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 Center および File ExchangeSurface 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