Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9188875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:07:03+00:00 2026-06-17T20:07:03+00:00

EDIT: I rephrased my question a bit, because I have a better understanding of

  • 0

EDIT: I rephrased my question a bit, because I have a better understanding of the problem now and there was a lot of unnecessary info in the first draft.

I am creating a standalone MATLAB application, which needs a toggle button that can initiate and stop a looping script.

Based on this helpful video, I was able to implement this idea like this in my gui.m file:

function startBtn_Callback(hObject, eventdata, handles)

    if get(handles.startBtn,'Value')
        set(handles.startBtn,'String','Stop Recording');
    else
        set(handles.startBtn,'String','Start Recording');
    end

    while get(handles.startBtn,'Value');
        disp('looping..');
        pause(.5);
    end

This script works as expected, but when I replace the contents of the while loop the function I would like to loop, the button stops working. It still toggles when I push it, but the callback only gets called the first time the button is pushed. Here is what my final code looks like:

function startBtn_Callback(hObject, eventdata, handles)

    if get(handles.startBtn,'Value')
        set(handles.startBtn,'String','Stop Recording');
        pause(.1);
    else
        set(handles.startBtn,'String','Start Recording');
        disp('Recording Stopped')
    end

    while get(handles.startBtn,'Value');
        myFunction();
    end

When I push the start button, this callback runs and the loop starts. The pause(.1) is needed to get the text to change – if I don’t include a pause, the loop initiates, but the text on the button does not change.

After this, no subsequent button pushes do anything. The button toggles on the GUI, but startBtn_Callback never gets called and the loop runs indefinitely. This is a problem because my end user will not have access to the MATLAB console.

To give a bit more information about my function: its a method that records audio for 5 seconds, does some processing, then outputs some graphs. I want this loop to repeat indefinitely until the user pushes stop.

I think that the issue is that MATLAB seems to only be able to run one function at a time, so when myFunction() is running, the callback can’t be initiated. The reason it worked in the first example is because there was a pause between loop calls. I can’t have this pause, because a requirement of the project is to record every possible second.

How can I make a reliable stop button for this process?

I am running MATLAB R2012b 32-bit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:07:04+00:00Added an answer on June 17, 2026 at 8:07 pm

    drawnow() is the function I was looking for. Putting that after myFunction() forces Matlab to handle any stacked up GUI calls before proceeding with the loop.

    This code creates a reliable start/stop toggle button for an indefinite and continuous process:

    function startBtn_Callback(hObject, eventdata, handles)
    
      if get(handles.startBtn,'Value')
          set(handles.startBtn,'String','Stop');
          drawnow();
      else
          set(handles.startBtn,'String','Start');
      end
      while get(handles.startBtn,'Value');
          myFunction();
          drawnow()
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I rephrased the question because I have not explained well. Let's see if
EDIT: I've completed rephrased the question as I've been able to simplify my problem
EDIT: following the first answer I have looked more into stackoverflow and rephrased the
EDIT: rephrased question for clarity of what I was wanting to achieve. I have
Edit (updated question) I have a simple C program: // it is not important
EDIT : sorry i've rephrased my question New to JQuery and need some assistance
EDIT: This question has changed as I have waited for an answer and done
From the .net 4.0 previews I have read until now there has been lots
EDIT: Rephrased the question: I want to use ActiveMQ as a messenger service between
EDIT: I'd better rephrase: How can I shift the GET-implementation of a Class property

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.