how do I keep a figure current? have tried "hold" and everything I could glean from Doc's and on line
8 views (last 30 days)
Show older comments
Tommy Franklin
on 13 Jan 2016
Commented: Tommy Franklin
on 14 Jan 2016
I do f=figure(myfile) so myfile should then be current. I do "hold on" and up pops a new figure, same with "set" and "plot". Has somebody plotted x,y on an existing figure created by uicontrol? I've tried every trick I can come up with. Frustration is ... this shoud be possible. Not a newby to matlab but this is new...thx in advance
3 Comments
Walter Roberson
on 13 Jan 2016
uicontrol does not create figures. Did you mean it was created in a callback function?
Accepted Answer
Walter Roberson
on 14 Jan 2016
function dummy
my_figure = figure(brute); % brute created with Guide
axes_handle = findall(my_figure,'type','axes');
axes(axes_handle);
hold on
plot([0 5], [6 6]);
plot([5 14], [8 8]);
However, much better is to specify the destination for every graphics operation!
function dummy
axes_handle = findall(brute,'type','axes');
hold(axes_handle, 'on');
plot(axes_handle, [0 5], [6 6]);
plot(axes_handle, [5 14], [8 8]);
hold(axes_handle, 'off');
This does not rely upon any particular figure or handle being the active handle. When you get into more complicated GUI you will find this very useful for debugging: otherwise if you are debugging and you accidentally touch something else then you would end up activating that other thing when you did not want to.
More Answers (1)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!