Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pause a process

Status
Not open for further replies.

ak501

Computer
Oct 27, 2005
4
0
0
DE
Hello friends,

I have a problem pausing a process from GUI interface in MATLAB.

So here are the details of my problem

I was trying to plot XY-graph.

So for that i made three buttons in the GUI

say

Plots
Pause ON
Pause OFF

when I press <Plots button> it plots from 1:1000 on x-axis and rand(1000,1) numbers on Y-axis

so I do this in different figure other than using GUI-axes property (as I need it that way)

plotting works fine,

but when I want to pause the plotting in between I cant do it

here is my code, please give some suggestions


plotss.m

function varargout = plotss(varargin)

<all default GUI stuff>

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)

plot_example




% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)

pause on

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)


pause off


plot_example.m

function plot_example
x=[1:1000];
y=rand(1000,1);
z=rand(1000,1);
a=[];
b=[];
c=[];
figure(2)
for i = 1:size(x,2)
a=[a;x(i)];
b=[b;y(i)];
c=[c;z(i)];

plotting(a,b,'r')
plotting(a,c,'b')
end

%plot(x,y);
%set(handles.ax,h);


function plotting(xx,yy,colors)
hold on
plot(xx,yy,colors)
drawnow




 
Replies continue below

Recommended for you

pause on just lets later pause statments go.

To pause with pause you want pause(n) or pause(inf)
or possibly waitforbuttonpress.

or probably better in this case uiwait and iuresume, which respect the gui a bit more.

I suggest :
function pushbutton2_Callback(hObject, eventdata, handles)
global fighandle
uiwait(fighandle)

function pushbutton3_Callback(hObject, eventdata, handles)
global fighandle
uiresume(fighandle)

in conjuction with passing the figure handle as a global from the plot_example function.

And also keeping track of the axes in the external figure, so that the plotting doesn't jump to the active object (being the form), when you make it active by clicking on it.

function plot_example
x=[1:1000];
y=rand(1000,1);
z=rand(1000,1);
a=[];
b=[];
c=[];
figure(2)
global fighandle;
fighandle = gcf;
axhandle = gca;
for i = 1:size(x,2)
a=[a;x(i)];
b=[b;y(i)];
c=[c;z(i)];

plotting(a,b,'r',axhandle)
plotting(a,c,'b',axhandle)
end

function plotting(xx,yy,colors,axhandle)
hold on (axhandle)
plot(axhandle,xx,yy,colors)
drawnow
 
Status
Not open for further replies.
Back
Top