Error in plot3: Vectors must be the same length
2 次查看(过去 30 天)
显示 更早的评论
Hey, so I'm trying to use this function to plot a 2D circle on a 3D space, but I get this annoying error every time and I can't understand why:
function plotcircle(ax,x,y,z,r,color)
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
zp = z*ones(1, length(ang));
if nargin == 6
plot3(ax, x+xp,y+yp, zp, 'Color',color);
else
plot3(ax, x+xp,y+yp, zp);
end
I've checked, and all 3 vectors are the same length and have 629 elements. Am I missing something?
Thank you.
4 个评论
Walter Roberson
2021-1-18
You were passing in the result of axis() instead of axes()
plotcircle(axes(), 1, 2, 3, 4, 'r')
function plotcircle(ax,x,y,z,r,color)
ang=0:0.01:2*pi;
xp=r*cos(ang);
yp=r*sin(ang);
zp = z*ones(1, length(ang));
if nargin == 6
plot3(ax, x+xp,y+yp, zp, 'Color',color);
else
plot3(ax, x+xp,y+yp, zp);
end
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!