Surface plot of vectors with x and y vectors as index
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have 3 vectors xx, yy and zz and I want the surface plot having the x and y axis coordinates as the indexes of the graph (surface plot by convention gives you the row and column indexes as the indexes for the surf plot graph). My zz vector is the z axis.
I can do
plot3(xx,yy,zz)
Which is good, but not exactly what I want. The plot3 function gives me the correct indexes on the graph, but nothing like a surf. I was looking at this example here however, I am getting errors. My code is below, however it is not working and I am getting an out of range error "Out of range subscript." where I call sub2ind.
xx = 31:120;
yy = 1:4:360;
zz = rand(size(xx));
[x,y]=meshgrid(xx,yy);
z=zeros(size(x));
z(sub2ind(size(z),xx,yy))=zz;
surf(x,y,z)
0 comentarios
Respuestas (1)
jonas
el 24 de Oct. de 2018
Editada: jonas
el 24 de Oct. de 2018
After meshgrid you need to interpolate. For example
z = griddata(xx, yy, zz, x, y)
Then you can plot
surf(x, y, z)
Surf plots are rectangular, always, although you can pad the edges with NaNs to make irregular shapes. The link you refer to use a triangular mesh, which is useful if you want a less regular shape without creating a rectangular grid.
0 comentarios
Ver también
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!