3D surface plot with three vector

조회 수: 9 (최근 30일)
Micangi
Micangi 2020년 8월 26일
댓글: Bjorn Gustavsson 2020년 8월 26일
I have a certain number of X,Y,Z vectors. I have to show a 3D representation of them and I have tryed with a plot3 function, as the following example:
for i=1:15:365 %i is the number of the x,y,z vectors
x=rand(1)*(1:1:10)
y=rand(1)*(1:1:10)
z=rand(1)*[0,9,12,21,20,18,15,11,6,0]
plot3(x,y,z)
hold on
end
However, I would like to show a 3D surface plot like in this Image.

채택된 답변

Bjorn Gustavsson
Bjorn Gustavsson 2020년 8월 26일
Since you have 3 1-D arrays you would first have to do some processing to get to a surface-plot. But you should start by looking at the help and documentation to trisurf - that is the first function I'd turn to in your case with very few points in your array.
If you have larger number of points it might be worthwhile to reinterpolate them to some regular grid. For that you should look up scatteredInterpolant (or TriScatteredInterpolant or griddata).
HTH
  댓글 수: 2
Micangi
Micangi 2020년 8월 26일
Actually I have vectors with larger number of point (more than 30000). I tried with the trisurf function by plotting every nth data point to reduce the computation but the plot was not the one expected.
Can you help me with catteredInterpolant (or TriScatteredInterpolant or griddata)?
Bjorn Gustavsson
Bjorn Gustavsson 2020년 8월 26일
1, dont reduce the number of points from 30000 (300 x 100 seems reasonable to me for modeling a 2-D surface) to 3000 (only 30 x 100, might be too few.).
2, From the help of scatteredInterpolant:
F = scatteredInterpolant(X,v) creates an interpolant that fits a surface of the form v = F(X) to the sample data set (X,v). The sample points X must have size NPTS-by-2 in 2-D or NPTS-by-3 in 3-D, where NPTS is the number of points. Each row of X contains the coordinates of one sample point. The values v must be a column vector of length NPTS.
So lets use that to build an interpolating function:
F = scatteredInterpolant(x(:),y(:),z(:),'natural','linear');
Then we define our [x,y]-grid and calculate the interpolated values:
[xi,yi] = meshgrid(linspace(min(x),max(x),101),linspace(min(y),max(y),151));
zi = F(xi,yi);
pcolor(xi,yi,zi),shading flat
That should give you neat surfaces. However, this will likely not be all that much faster than trisurf. The bulk of the job will be spent building the triangulation. If you have a fixed number of points that doesn't vary over the loop then you should build the interpolating surface once. If you have 30000 different points for each time in the loop this will take some time, to me it seems tricky to avoid and you'll have to stock up on patience. In that case save the interpolating functions once they've been calculated so that you at least have them pre-calculated for next time to redo the analysis...

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

추가 답변 (0개)

카테고리

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