Drexel dragonThe Math ForumDonate to the Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Updating LEGEND in loop after CLA
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 125
Registered: 5/4/11
Updating LEGEND in loop after CLA
Posted: Feb 21, 2013 1:13 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

anim_fig = figure('name','Animation','toolbar','figure');
hold on
axis([-1 1 -1 1 -1 1])
axis vis3d
axis square

%% Set up and display the legend
empty = plot3(NaN,NaN,NaN,'LineStyle','none');
legend_colors = [empty];
legend_strings = {' LEGEND '};

traj_start = plot3(0,0,0,...
traj_end = plot3(1,1,1,...
'Marker','x','LineStyle','none','MarkerEdgeColor',[0.1 0.8 0.1]);
legend_strings = {legend_strings{:}, 'Starting Position','Ending Position'};
legend_colors = [legend_colors; traj_start(1);traj_end(1)];

targeted_goal = plot3(0,0,0,...
legend_strings = {legend_strings{:}, 'Current Target'};
legend_colors = [legend_colors; targeted_goal(1)];

hleg = legend(legend_colors,legend_strings{:},'Location','NorthEastOutside');

animates_per_figure = 3; %how many to plot before we clear the screen and do it again
EmT = 0; %Remembers if last target existed
Targets_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

TargExist = Targets_Exist(trial_index);
if(TargExist ~= EmT)
%Change the legend
EmT = ~EmT;
legend_strings{4} = 'NO TARGET';
legend_strings{4} = 'Current Target';

end %Close animates_per_figure loop

All suggestions, ideas, work arounds, kludges welcome.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum 1994-2015. All Rights Reserved.