필터 지우기
필터 지우기

Error in plot3: Vectors must be the same length

조회 수: 1 (최근 30일)
Avi Michaely
Avi Michaely 2021년 1월 18일
댓글: Avi Michaely 2021년 1월 18일
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
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
Avi Michaely
Avi Michaely 2021년 1월 18일
Ah * facepalm *
Thanks, it's working now :)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by