From: Adam on 7 Jun 2010 19:07 Hi, I would like, in a loop, to plot a dynamic line. What I'm looking for it the line start at zero, then a random point is generated and the line goes to that point (1,randompoint1) then a pause, then it extends to (2,randompoint2) etc.. This should continue until the loops stops. It should be an easy task but I can't find a way to do it. Here is an example of what I mean for the end result except that months would just be 1,2,3..n. http://edynblog.files.wordpress.com/2007/07/line-graph-days-on-market.jpg
From: Walter Roberson on 7 Jun 2010 19:32 Adam wrote: > I would like, in a loop, to plot a dynamic line. What I'm looking for it > the line start at zero, then a random point is generated and the line > goes to that point (1,randompoint1) then a pause, then it extends to > (2,randompoint2) etc.. This should continue until the loops stops. It > should be an easy task but I can't find a way to do it. for pointnum = 1:1000 thisx = .... %random new position thisy = .... %random new position if pointnum == 1 linehandle = plot([0 thisx],[0 thisy]); else pause(1/2); %seconds oldx = get(linehandle, 'XData'); oldy = get(linehandle, 'YData'); set(linehandle, 'XData', [oldx thisx], 'YData', [oldy thisy]); end end
From: Adam on 7 Jun 2010 19:40 Walter Roberson <roberson(a)hushmail.com> wrote in message <hujvl8$gvb$1(a)canopus.cc.umanitoba.ca>... > Adam wrote: > > > I would like, in a loop, to plot a dynamic line. What I'm looking for it > > the line start at zero, then a random point is generated and the line > > goes to that point (1,randompoint1) then a pause, then it extends to > > (2,randompoint2) etc.. This should continue until the loops stops. It > > should be an easy task but I can't find a way to do it. > > for pointnum = 1:1000 > thisx = .... %random new position > thisy = .... %random new position > > if pointnum == 1 > linehandle = plot([0 thisx],[0 thisy]); > else > pause(1/2); %seconds > oldx = get(linehandle, 'XData'); > oldy = get(linehandle, 'YData'); > set(linehandle, 'XData', [oldx thisx], 'YData', [oldy thisy]); > end > end Thats perfect thanks. My actual implementation is going be a bit more complex but this should be enough for me to get it done. Thanks again.
|
Pages: 1 Prev: NIDAQ USB-6009 Next: Computation time reduction between using "parfor" and "for" loops |