×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Pause a process

Pause a process

Pause a process

(OP)
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




RE: Pause a process

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

RE: Pause a process

(OP)
Hello SoundNSW

It works thx for your help.




Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources