Plot function for two moving points with different velocities

4 ビュー (過去 30 日間)
Yashashwani xxx
Yashashwani xxx 2017 年 11 月 21 日
回答済み: Image Analyst 2017 年 11 月 21 日
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

回答 (1 件)

Image Analyst
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.

カテゴリ

Help Center および File ExchangeAnalysis of Variance and Covariance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by