Surface plot of vectors with x and y vectors as index
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
jonas
2018-10-24
编辑:jonas
2018-10-24
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!