I've got a custom function similar to COMET (shows an animation of a trajectory). After a few iterations, I clear the figure using CLA and start plotting again. This is all happening in a for loop.

Being plotted in the figure is the trajectory and the target (where the trajectory should end up). I just ran into a situation where the target doesn't exist for a sample and I want the legend to reflect this. I was hoping to remove the "Target" entry from the legend and then put it back in on subsequent trials when it does exist. That seemed impossible. Alternatively, I was hoping to use SET to change the text of the entries, changing "Current Target" to "NO TARGET" However, when I do that, the strings are condensed in the legend and displayed one on top of the other. This doesn't happen if I don't use CLA. (I haven't looked into using delete instead of CLA to remove old targets, but I'm guessing it'd still be a problem because the handles to the object would go away.)

I've condensed the code I'm running into this snippit.

UseCLA = true; %toggle this to see the desired/undesired behavior in the legend

animates_per_figure = 3; %how many to plot before we clear the screen and do it againEmT = 0; %Remembers if last target existedTargets_Exist = [0 1 1 0 0 1 1 1 0]; %A practice vector of whether targets exist or not%% Done with setup. Now let's actually loop through all the trials.for trial_index = 1:length(Targets_Exist) if(~mod(animated_trials,animates_per_figure))% After we've plotted a certain amount of reaches, clear the screen and continue animating the data if(UseCLA) cla(anim_fig); end end