MATLAB: How to keep a figure current? have tried “hold” and everything I could glean from Doc’s and on line

frustrated plotter

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

Best Answer

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.