I'm trying to use plot() several times without using clf because this causing my animation to blink. In the discussion in here [plot is blinking when clearing figure], a clever solution suggested by @Walter Roberson is to update data rather than creating a new object for plot every iteration. I've managed to create the following minimal working example as a start point for my problem. For each function (i.e. y1,y2), I need to create a new gobjects so that I can update their data rather than calling clf which causes terrible. The problem with the aforementioned approach is the fact that I need to create gobjects for each drawable thing. In my actual application, drawable things are unknown a priori. In the simuation, I have to add them depending on specific conditions. My question is how can I modify the below code in a clever way to use a shared gobjects and at the same time avoid using clf.
objarray = gobjects(1,2);
objarray(1) = plot(x,y1,'LineWidth',2);
objarray(2) = plot(x,y2,'r','LineWidth',2);
The above code can be done with clf as follows which is not working for my case.