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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:24:12+00:00 2026-05-20T09:24:12+00:00

I have a Matlab script consisting of several cells that should all be able

  • 0

I have a Matlab script consisting of several cells that should all be able to execute independently (i.e. I might need to execute one cell in order to execute another, but until I clear the workspace I should be able to execute the second cell again without executing the first one). The code in these cells sometimes fails (of course), and in case they do, I want to run a specific command.

Since the code spans across several independent cells, I can’t use a try/catch block to accomplish this – not unless I put one try/catch block in each cell, which I don’t want to. Each cell is pretty short (a few lines with function calls, mostly), so introducing a try/catch block in every cell would probably double the length of the script.

Specifically, I want to open a log file (diary filename.log) in the first cell, which closes automatically (diary off) after an error occurs (and is logged) from any cell. This setting should be on at least until the log file is closed again, and should be settable programatically (I want to set it in the same cell I open the log file).

How do I accomplish this?

  • 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-20T09:24:13+00:00Added an answer on May 20, 2026 at 9:24 am

    If you want to keep your code as a script, your best solution is to put a try/catch block around each cell.

    Otherwise, you can create a function to wrap around your script. The function syntax allows you to set ‘dbstop if error’, so that code execution halts on an error which allows you to inspect variables and pinpoint why things went wrong.

    function output = run(listOfCells,input)
    %#RUN evaluates the cells listed in listOfCells
    
    try
    
    diary filename.log
    
    if any(listOfCells==1)
    %# evaulate cell 1
    
    end
    
    if any(listOfCells==2)
    %# evaluate cell 2
    
    end
    
    ...
    
    catch
    %# close the diary in case of error
    diary off
    end %# try
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a matlab script, lets call it master.m, that loads a file called
I have to write a Matlab script that does this: The input is 2
I have developed code on a m-file script in Matlab that communicates with a
I have a matlab script which executes 5 algorithm sequentially. All these 5 algorithms
I have a Matlab script that requires a function in a DLL, and calls
I have a matlab script lets say image_process.m and the function image_process accepts one
I have a matlab script that converts the images from png to jpeg. However
I have matlab function that calls a Perl script which converts a large text
I have been currently using a Matlab script that plots a function and prints
All, I have a python script that uses OpenCV to calibrate a camera. It

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.