MATLAB: Multiple plots using a method on single axis

for loopMATLABplot

I have a method that plots an array of data onto an axes in my GUI. I want to be able to call this method in a for loop and all the data that is plotted be on the same axes and not reset every time the method is called. Is this possible?

Best Answer

Sure, just set hold on for the figure after the first plot...
NB: To cycle colors/linestyles you'll have to increment and pass a color/linestyle argument for each; otherwise Matlab starts counting over from the beginning of the default order. I think this is a glaring weakness in the controllability as it's such a common desire to add incrementally as opposed to always having all the data that can make a single call in which case the colors/linestyles do cycle automagically. But, several requests for it as an enhancement over the years went unheeded so I've given up... :(