Surface plot of vectors with x and y vectors as index

조회 수: 7 (최근 30일)
Dane Hylton
Dane Hylton 2018년 10월 24일
편집: jonas 2018년 10월 24일
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)

답변 (1개)

jonas
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.

카테고리

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