2013-01-18 80 views
1

我试图做一个循环内的阴谋,它只打印最后一个阴谋。MATLAB:在一个循环中的阴谋

我该如何解决?

我试图在绘图定义后使用hold ondrawnow,但它不起作用。

这是我的代码:

for t=1:5 
    alive = Game(World , Generations, speed); 
    plot(hplot2,1:Generations,alive); 
end 

回答

2

hold on应该工作。试试这个:

figure 
hplot2=gca; 
hold on 
for t=1:5 
    alive = rand(1,Generations); 
    plot(hplot2,1:Generations,alive); 
end 
2

坚持一个“数字”一直对我有效。

for t=1:5 
    alive = Game(World , Generations, speed); 
    figure; 
    plot(hplot2,1:Generations,alive); 
end 
1

既然你已经通过轴手柄来plot,你只需要把像pause(0.1)内循环,而原始来源将工作。

1

你也可以使用figure(t)有5个不同的数字。

0

如果函数Game(World , Generations, speed)是确定性函数 - 它为每个t提供相同的输出。因此,每plot命令有正好相同的输出,你不能区分第一个和最后一个图。

尝试plot随机系列在每次迭代(如在shoelzer的答案),看看你是否看到所有5个地块。

此外,您可能想要使用hold all而不是hold on:这样每个图将从颜色映射获得不同的颜色。