필터 지우기
필터 지우기

Random number of points moving with given velocity

조회 수: 1 (최근 30일)
Anu Sharma
Anu Sharma 2023년 8월 29일
댓글: Anu Sharma 2023년 8월 29일
How to write a code for random number of points moving in an area at a given velocity.
There are random number of points ( 50) in an area of 600*600, moving from one point to another at given velocity (10m/s).
The code for moving one point in an area of 25*25 is given below. Similarly I want to move random number (>=50) of points in the given area (600*600).
clc
close all
figure;axis square;
set(gca,'XLim',[0,25],'YLim',[0,25]);
MOVINGPOINT = rectangle('Parent',gca,'Position',[4.5,4.5,1,1],'Curvature',[1,1]);
startPos = [2,2];
endPos = [20,20];
vel = 10;
[x_dis] = endPos(1)-startPos(1);
[y_dis] = endPos(2)-startPos(2);
Dis = sqrt(x_dis^2+y_dis^2);
Ttime = Dis/vel;
x_vel = (vel*x_dis)/Dis;
y_vel = (vel*y_dis)/Dis;
t = 0.01:0.01:Ttime;
X =startPos(1)+x_vel*t;
Y = startPos(1)+y_vel*t;
trajectory = [X;Y];
for frameNo = 1:length(t)
set(MOVINGPOINT,'Position',[trajectory(1,frameNo)-0.25,trajectory(2,frameNo)-0.25,0.5,0.5]);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
frames(frameNo) = getframe;
end
Please help me with the random number (>=50) of points moving with the given velocity and to calculate the trajectory of the points.

답변 (1개)

Image Analyst
Image Analyst 2023년 8월 29일
You need a comma after 'Position' :
set(MOVINGPOINT,'Position', [trajectory(1,frameNo)-0.25,trajectory(2,frameNo)-0.25,0.5,0.5]);
  댓글 수: 1
Anu Sharma
Anu Sharma 2023년 8월 29일
ok
but please tell me how I can extend the code for more number of points. This code is for moving one point only

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by