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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:38:24+00:00 2026-06-01T16:38:24+00:00

I’m writing a matlab script where I’d like to know the name of the

  • 0

I’m writing a matlab script where I’d like to know the name of the script which is one step up in the stack. The reason I need this is that I’m writing a helper script to be called to assert some basic facts about the workspace before engaging in heavier calculations, and the helper script should be able to give error messages when calling the calculation scripts.

I’ve tried using mfilename and dbstack, but I do not manage to get anything but the name of the helper script from them.

To explain further, I have the following scripts:

  • verify_base_conditions: the helper script, called on one of the first lines in
  • heavy_stuff_calculation and
  • sweet_mother_of_algorithms.
  • general_entry_point: a script where I gather common workflows in cells

I try to keep the entry point script as small as possible, and refactor heavier calculations (or anything that needs more than a few lines, really) into task-based, re-usable scripts. If I, from the entry point script, call sweet_mother_of_algorithms and the basic conditions for this script to run are not fulfilled, I want to see an error message like

Error: this_cool_var must be defined when running sweet_mother_of_algorithms
general_entry_point line 15

I tried using

error(['this_cool_var must be defined when running ' mdfilename])

and other similar constructs, but I couldn’t make the error message say anything but verify_base_conditions.

How do I find the name of the script running one level up in the stack?

(Note: I’m not interested in finding the script running at the bottom of the stack – that will almost always be general_entry_point. I’m just interested in getting the name of the script that called verify_base_conditions.)

  • 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-01T16:38:25+00:00Added an answer on June 1, 2026 at 4:38 pm

    dbstack should work for this. I think this is an analogous set-up to yours:

    a.m:
      b;
    
    b.m:
      c;
    
    c.m:
      stack = dbstack;
      for i=1:3
        disp(stack(i));
      end
    

    When I run a;, this prints out the whole stack, including b (which I think it was you want – the second-top item on the call stack.

    Alternatively, although this probably gives exactly the same result, you could throw and catch an error and look at its stack:

    c.m:
      try
        error('What is on the call stack?');
      catch e
        for i=1:3
          disp(e.stack(i));
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I would like to run a str_replace or preg_replace which looks for certain words
I have an autohotkey script which looks up a word in a bilingual dictionary
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT

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.