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

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.

Risposte (2)

Torsten
Torsten il 7 Apr 2025
Modificato: Torsten il 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 Commenti

Yes that was my backup solution but I wanted to know if there was something less 'brute' / cleaner
I think it is as clean as you can get. And why do you think it's brute ?

Accedi per commentare.

Categorie

Prodotti

Release

R2014a

Richiesto:

il 7 Apr 2025

Risposto:

il 7 Apr 2025

Community Treasure Hunt

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

Start Hunting!

Translated by