How to draw a 3D surface with all the given discrete points?

조회 수: 27 (최근 30일)
Danny 2023년 12월 4일
댓글: Mathieu NOE 2023년 12월 4일
I am trying to draw data from several curves into a 3D surface. I have extracted the points in the curves as discrete data points and tried to draw a surface plot based on scatter data. The problem is that discrete points in each curve may have multiple Z-values at the same X-Y coordinate. Command 'griddata' and 'surf' have been used, but it gives warning of duplicate data points have been detected and averaged.
I have realized that the rule of 'griddata' is that only the unique Z-value can be used in the xy plane, otherwise the average will be used. The data is contained in the attachment, and the code and results are given below.
close all; clear all
load XYZ_data
% figure
How can I get a smooth surface with all the given data? Any comments will be much appreciated.
Discrete data

채택된 답변

Mathieu NOE
Mathieu NOE 2023년 12월 4일
of course I tried the standard solutions (surfir, griddata etc...) but as your shape is very specific , therefore also a specific code for you
try this
load XYZ_data
samples = numel(x);
[xu,ia,ic] = unique(x);
unique_curves = numel(ia);
N = samples/unique_curves; % this is length of one curve
% main loop
for k =1:N
ind = k:N:samples;
xx = x(ind);
yy = y(ind);
zz = z(ind);
% Interpolate the scattered data
xd(k,:) = linspace(min(xx),max(xx),100);
yd(k,:) = interp1(xx,yy,xd(k,:));
zd(k,:) = interp1(xx,zz,xd(k,:));
title('data points')
h = surf(xd,yd,zd);
title('surface plot')
  댓글 수: 2
Danny 2023년 12월 4일
Thank you! That's exactly what I wanted. You have solved my problem.
Best regards,

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

추가 답변 (1개)

Chunru 2023년 12월 4일
편집: Chunru 2023년 12월 4일
load(websave("XYZ_data.mat", ""))
Name Size Bytes Class Attributes cmdout 1x33 66 char x 2870x1 22960 double y 2870x1 22960 double z 2870x1 22960 double
T = delaunay(x, y);
Warning: Duplicate data points have been detected and removed.
Some point indices will not be referenced by the triangulation.
% Seems that there are duplicate point for x, y (in addition to z?)
trisurf(T, x, y, z, "EdgeColor","none", "FaceColor","interp");
xlabel("x"); ylabel("y")
view(80, 30)
  댓글 수: 1
Danny 2023년 12월 4일
Thanks Chunru.
Perhaps I should explain my question further. Actually, these discrete data come from 5 curves, and I want to draw a surface that contains these curves. In other words, I want to restore these data completely on a surface. Commands "trisurf" or "surf" do give the rough shape of the surface, but the key is how to preserve these duplicate values.

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


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


Community Treasure Hunt

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

Start Hunting!

Translated by