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)
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
Tommy Franklin
Tommy Franklin on 13 Jan 2016
Edited: Walter Roberson on 14 Jan 2016
thanks Stephen, Walter -
function dummy
my_figure = figure(brute); % brute created with Guide
figure_handle = findall(my_figure,'type','axes'); %OK to here.
hold on % unwanted Figure1 pops up --- my_figure not current!
plot([0 5], [6 6]); % goes to Figure1 rather than my_figure
plot([5 14], [8 8]); % goes to Figure1
supposedly the first line of code here makes my_file the current. Want this to be one way - no callback

Sign in to comment.

Accepted Answer

Walter Roberson
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)

Steven Lord
Steven Lord on 13 Jan 2016
Check the HandleVisibility property of your figure window.
  1 Comment
Tommy Franklin
Tommy Franklin on 13 Jan 2016
Thanks Steven - HandleVisibility property for the my_figure is "callback". my_figure has some buttons that execute callback and those are OK. The plots intended for the my_figure axes1 is one way only - from code to my_figure/ axes1. Funny thing - I got the thing working properly when first attampted but when I went back a little later

Sign in to comment.

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!