Matlab function that tells the full path of from where the function has been called

3 views (last 30 days)
Not sure the title is very clear so I'll describe my project :
There is this class 1 in Desktop/Folder/Sub_Folder1/@class1/class1.m in which a function1 is coded.
There is this class 2 in Desktop/Folder/Sub_Folder2/@class2/class2.m in which a function 2 is coded.
When function2 is called, it calls function1 that displays a message. There will be in the future function3, 4, 5.. that will also call function1 and display a message so I want to know in the message what function triggered function1.
I tried dbstack but it doesn't give me the whole path. only 'class2.function2'
Also, for some reason I'm in matlab2014a.

Answers (2)

Torsten
Torsten on 7 Apr 2025
Edited: Torsten on 7 Apr 2025
What about passing the full path where the function is located from the respective functions 2,3,4,5... to function1 ?
See
together with fileparts() to extract the directory portion, and fullfile() to construct the new file name.
  2 Comments
Gauthier
Gauthier on 7 Apr 2025
Yes that was my backup solution but I wanted to know if there was something less 'brute' / cleaner
Torsten
Torsten on 7 Apr 2025
Edited: Torsten on 7 Apr 2025
I think it is as clean as you can get. And why do you think it's brute ?

Sign in to comment.


Walter Roberson
Walter Roberson on 7 Apr 2025
Use dbstack , possibly with the -completenames option.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products


Release

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!