X=randi([1,5],3,1);
Y=randi([1,5],3,1);
for i=1:3;
Xnew(i)=[X(i,1)+.6];
Xn=Xnew';
Ynew(i)=[Y(i,1)+.4];
Yn=Ynew';
end
plot(Xn,Yn,'kd');
grid on;
hold on;
D2X=randi([1,5],3,1);
D2Y=randi([1,5],3,1);
plot(D2X,D2Y,'ro');
hold off;
axis([1,50,1,50]);
我的问题就像在第一天源生成三个粒子然后这三个粒子随着地下水速度移动,第二天三个粒子再次由源生成,第三天又三个粒子由源和前者生成粒子将随着地下水的速度移动,源产生一定范围内的粒子只能说(0-5)。这将持续365天。
答案 0 :(得分:0)
我认为这是你正在尝试做的事情。如果我误解了,请澄清你的问题。
xyRange=[1,5]; %// Starting xy range of particles
numP=3; %// Number of particles generated each day
vx=0.6; vy=0.4; %// x and y velocity
numDays=365; %// Number of days to generate particles
X=[]; Y=[]; %// Vectors start out empty
for day=1:numDays
%// Generate numP particles and add to end of vectors X and Y
X=[X;randi(xyRange,numP,1)];
Y=[Y;randi(xyRange,numP,1)];
%// Move all the particles
X=X+vx;
Y=Y+vy;
end
此版本会在粒子生成当天移动它们。如果您只想在生成粒子的第二天开始移动粒子,您可以稍微改变一下:
xyRange=[1,5]; %// Starting xy range of particles
numP=3; %// Number of particles generated each day
vx=0.6; vy=0.4; %// x and y velocity
numDays=365; %// Number of days to generate particles
%// Generate first numP particles
X=[randi(xyRange,numP,1)];
Y=[randi(xyRange,numP,1)];
for day=2:numDays %// Note we've already done Day 1
%// Move all pre-existing particles
X=X+vx;
Y=Y+vy;
%// Generate numP particles and add to end of vectors X and Y
X=[X;randi(xyRange,numP,1)];
Y=[Y;randi(xyRange,numP,1)];
end
在任一版本的末尾,生成的第一个粒子将位于X(1:3),Y(1:3)
,生成的最后一个粒子将位于X(end-2:end),Y(end-2:end)
。
我不确定您是想要每天还是仅在年底进行策划,但我相信您可以解决这个问题。