3D surface plot with three vector

7 visualizaciones (últimos 30 días)
Micangi
Micangi el 26 de Ag. de 2020
Comentada: Bjorn Gustavsson el 26 de Ag. de 2020
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.

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 26 de Ag. de 2020
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 comentarios
Micangi
Micangi el 26 de Ag. de 2020
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 el 26 de Ag. de 2020
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...

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by