简体   繁体   中英

matlab creating and plotting 3d points

I'm trying to create a meshgrid of many many points and plotting it. It is working this way:

for x=roadLeft:10:roadRight
    for y=0:10:50
       for z=0:10:roadTop
         points(1,i)= x;
         points(2,i)= y;
         points(3,i)= z;
         i=i+1;
      end
    end
end
plot3(points(1,:),points(2,:),points(3,:), '*b')

but this is ugly and I'm sure there's a way to do it with meshgrid. I tried to do:

[X,Y,Z] = meshgrid(roadLeft:10:roadRight, 0:10:50,0:10:roadTop);
surf(X,Y,Z)

but I'm getting this error:

CData must be an M-by-N matrix or M-by-N-by-3 array

Error in graph3d.surfaceplot>localConstructor (line 136)
h = graph3d.surfaceplot(argin{:});

Error in graph3d.surfaceplot (line 7)
h = localConstructor(varargin{:});

Error in surf (line 101)
hh = double(graph3d.surfaceplot(args{:},'parent',parax));

what is the problem and how can I do it right?

下一行允许您绘制由meshgrid创建的3D点:

plot3(X(:), Y(:), Z(:), '*b')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM