- pause
- drawnow
- figure
- uiwait
- waitfor
How to switch between figures while simultaneously plotting?
38 次查看(过去 30 天)
显示 更早的评论
with the script below, when i click compute button, a new figure will pop up plotting(x,y) continuously. During this period I'm not able to "check" the "Add" checkbox. Bcz, i couldn't switch between figures while it is plotting. Is there anyway to overcome this?
function simpleGUI
hFig = figure('Visible','off', 'Menu','none', 'Name','Calculator', 'Resize','off', 'Position',[100 100 350 200]);
movegui(hFig,'center') %# Move the GUI to the center of the screen
radiobtn = uicontrol('Style','checkbox', 'Parent',hFig, 'HandleVisibility','off','value',0, 'Position',[15 150 70 30], 'String','Add', 'Tag','alpha');
uicontrol('Style','pushbutton', 'String','Compute', 'Position',[200 50 60 25], 'Callback',{@button_callback});
set(hFig, 'Visible','on') %# Make the GUI visible
x = 1:10;
y = 1:10;
a = get(radiobtn,'value');
%# callback function
function button_callback(src,ev)
h = figure('Menu','none', 'Name','plotter', 'Resize','off','CloseRequestFcn','delete(gcbf)');
while(ishandle(h))
figure(h);
if ishandle(h)
plot(x,y);
y(1) = y(1)+0.01;
end
end
end
end
0 个评论
回答(1 个)
Walter Roberson
2015-9-28
In the loop that is doing the plotting, you need to add one of the following calls:
2 个评论
John Hatrick
2016-11-12
Know how to switch between the figures? I want to jump back and forth during between simulation steps.
Walter Roberson
2016-11-13
Do not do that. Instead, "parent" all your graphics calls. That is, for every single graphics operation possible, tell it which axes or which line or which control or which figure it has to apply to.
In every case, unless you can pass in an axes as the first parameter, or pass in the handle to operate on, or give a 'Parent' name/value pair, then you cannot control what will happen if you switch figures or what happens if the user drops into debugging mode -- even if all they do is trigger a breakpoint and continue, chances are that the "current" figure or axes will be disrupted.
fig = figure(); %record that handle!
ax = subplot(1, 2, 1, 'Parent', fig); %tell it *which* figure you are drawing in
ph = plot(ax, rand(1,10)); %tell it which axes to draw on
hold(ax, 'on'); %tell it which axes to hold
set(ph, 'Marker', '*') %be specific about what handle you are affecting
xlabel(ax, 'x Label 121'); %tell it which axes to affect
set(ph, 'XData', 5:50, 'YData', cos(5:50)); %update an existing handle for efficiency!
If you do this consistently, every single time, then you do not need to "switch" figures, because you are never dealing with "active" figures.
There are some operations such as bode() which do not permit figure or axes to be specified and instead always clobber everything in the current figure. Those are unfortunate, and Mathworks really should fix that.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!