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

  • Home
  • SEARCH
  • 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 955795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:26:31+00:00 2026-05-16T00:26:31+00:00

Is there any way to stop the execution of a matlab program from the

  • 0

Is there any way to stop the execution of a matlab program from the debugger like ctrl+c does, but then being able to continue execution (like you can in say c#)?

If not, is there any better way to workaround this other than trying to pre-emptively set break points or dbstop statements in your matlab code?

I would like to be able to interrupt a long running simulation to look at the current state and then continue the simulation.

The two options I’m currently using/considering are

  1. dbstop commands (or (conditional) breakpoints) in the code.
    Drawback is that sometimes I don’t want to stop the simulation for a few hours, sometimes want to stop after only a few seconds (and I don’t necessarily know that in advance) and this doesn’t work well with this approach: If I set the break condition to break every 5 minutes, I can’t leave matlab running for hours without interaction. If I set the condition to higher, I have to wait too long for the condition to hit.

  2. include code to save the workspace every few seconds/minutes and import the workspace into a second matlab instance. Drawback is that this is a huge hassle and also doesn’t necessarily allows me to resume the simulation with the state of the saved workspace then step through the code for a few iterations.

I’m hoping there is a better solution than either of the 2. Thanks for any advice!

Edit: I think what I’m going to do is write simple matlab function that checks an environment variable or a file on disk every iteration and calls dbstop if I set a flag in this file or env. This way I can control when (and if needed which of several) the breakpoint hits from outside matlab by editing the file. Messy, but should work.

  • 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-05-16T00:26:32+00:00Added an answer on May 16, 2026 at 12:26 am

    This is not necessarily the best way, but you could simulate a file-based signal/interrupt framework. It could be done by checking every once in a while inside the long simulation loop for the existence of a specific file. If it does, you enter interactive mode using the keyboard command.

    Something along the lines:

    CHECK_EVERY = 10;    %# like a polling rate
    
    tic
    i = 1;               %# loop counter
    while true           %# long running loop
        if rem(i,CHECK_EVERY) == 0 && exist('debug.txt','file')
            fprintf('%f seconds since last time.\n', toc)
            keyboard
            tic
        end
    
        %# ... long calculations ...    
    
        i = i + 1;
    end
    

    You would run your simulation as usual. When you would like to step in the code, simply create a file debug.txt (manually that is), and the execution will halt and you get the prompt:

    2.803095 seconds since last time.
    K>> 
    

    You could then inspect your variables as usual… To continue, simply run return (dont forget to temporarily rename or remove the file). In order to exit, use dbquit


    EDIT: Just occurred to me, instead of checking for files, an easier solution would be to use a dummy figure as the flag (as long as the figure is open, keep running).

    hFig = figure; drawnow
    while true
        if ~ishandle(hFig)
            keyboard
            hFig = figure; drawnow
        end
    
        %# ...
        pause(0.5)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There doesn't seem to be any tried and true set of best practices to
Is there a way to test if a collection is already initialized? try-catch only?
This is beyond both making sense and my control. That being said here is
I would like to remove/delete a migration file. How would I go about doing
If all tables I want to delete from have the column gamer_id can i
I am attempting to pull some information from my tnsnames file using regex. I
I'm trying to build a C++ extension for python using swig. I've followed the
We manage a site for a medical charity. They have a number of links
I've found several jQuery syntaxes for nullifying the enter on a form. First one:
I notice in several API's, that you may create a struct which is used

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.