Plot function for two moving points with different velocities
조회 수: 3 (최근 30일)
이전 댓글 표시
I have the following code but it gives an error undefined function or variable 'x'. Can anyone please help me in this? plot(x, y, 'b');
car = line([], [], 'MarkerSize', 10, 'Color', 'r');
carx = x(1); cary = y(1);
numxy = length(x);
aimidx = 2;
numv = length(v);
vidx = 0;
speed = 0;
while true
if speed <= 0
carm = 'x';
set(car, 'XData', carx, 'YData', cary, 'Marker', carm);
drawnow;
if vidx >= numv || aimidx > numxy
break; %done following path
end
vidx = vidx + 1;
speed = v(vidx);
continue;
end
deltax = x(aimidx) - carx;
deltay = y(aimidx) - cary;
aimdist = sqrt(deltax.^2 + deltay.^2);
if aimdist <= speed
carx = x(aimidx);
cary = y(aimidx);
aimidx = aimidx + 1;
speed = 0; %flag to draw current point and move to next v
continue;
end
carx = carx + speed * deltax ./ aimdist;
cary = cary + speed * deltay ./ aimdist;
if abs(deltax) >= abs(deltay)
if deltax > 0
carm = '>';
else
carm = '<';
end
elseif deltay > 0
carm = '^';
else
carm = 'v';
end
set(car, 'XData', carx, 'YData', cary, 'Marker', carm);
drawnow;
end
댓글 수: 0
답변 (1개)
Image Analyst
2017년 11월 21일
If the first line of your code is this:
plot(x, y, 'b');
then why do you think x and y should have any values when you call plot()? You need to set them equal to something before you call plot.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!