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 7062563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:36:32+00:00 2026-05-28T04:36:32+00:00

I have a matlab script which executes 5 algorithm sequentially. All these 5 algorithms

  • 0

I have a matlab script which executes 5 algorithm sequentially. All these 5 algorithms needs to run for 10 different initialization.

Whenever there is an error in i-th initialization, the script exit with an error message. I fix the issue(say, data issue) and start running the script again which executes from the first initialization.

I dont want to my code to run for previously executed initialization. ( from 1 run to i-1 the run)

One way is to reassign the value of index to start from i, which in turn require to modify the scrip everytime again and again.

Is there any way to restart the script from the i-th initialization onwards which dont require to modify the script?

  • 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-28T04:36:33+00:00Added an answer on May 28, 2026 at 4:36 am

    Another technique you might like to consider is checkpointing. I’ve used something similar with long-running (more than one day) loops operating in an environment where the machine could become unavailable at any time, e.g. distributed clusters of spare machines in a lab.

    Basically, you check to see if a ‘checkpoint’ file exists before you start your loop. If it does than that suggests the loop did not finish successfully last time. It contains information on where the loop got up to as well as any other state that you need to get going again.

    Here’s a simplified example:

    function myFunction()
    
      numIter = 10;
      startIter = 1;
    
      checkpointFilename = 'checkpoint.mat';
    
      % Check for presence of checkpoint file suggesting the last run did not
      % complete
      if exist(checkpointFilename, 'file')
        s = load(checkpointFilename);
        startIter = s.i;
        fprintf('Restarting from iteration %d\n', startIter);
      end
    
      for i = startIter:numIter
        fprintf('Starting iteration %d\n', i);
        expensiveComputation();
        save(checkpointFilename, 'i');
      end
    
      % We succefully finished. Let's delete our checkpoint file
      delete(checkpointFilename);
    
      function expensiveComputation()
        % Pretend to do lots of work!
        pause(1);
      end
    
    end
    

    Running and breaking out with ctrl-c part way through looks like this:

    >> myFunction
    Starting iteration 1
    Starting iteration 2
    Starting iteration 3
    Starting iteration 4
    Operation terminated by user during myFunction/expensiveComputation (line 27)
    
    In myFunction (line 18)
        expensiveComputation();
    
    >> myFunction
    Restarting from iteration 4
    Starting iteration 4
    Starting iteration 5
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script for importing text files into matlab which include hourly
I have a Matlab script consisting of several cells that should all be able
I have matlab function that calls a Perl script which converts a large text
I have to write a Matlab script that does this: The input is 2
I have written a simple brainfuck interpreter in MATLAB script language. It is fed
I have developed code on a m-file script in Matlab that communicates with a
I have a MATLAB class which contains a reference to a java object classdef
I have a function in MATLAB which takes another function as an argument. I
I have a Matlab script that requires a function in a DLL, and calls
I like to create a report generation script in Matlab. Suppose we have a

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.