How can we know whether the current execution of command is conducting inside a function or not?
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Saang Bum Kim
el 23 de Oct. de 2021
Comentada: Image Analyst
el 24 de Oct. de 2021
How can we know whether the current execution of command is conducting inside a function or not?
When I develop a function, I frequently check some parts of the code for the function in base command envirenment.
I wonder is there any method to identify whether the current execution is conducting inside of a function or
it is conducting in the base environment.
Thanks in advance !!!
0 comentarios
Respuesta aceptada
Walter Roberson
el 23 de Oct. de 2021
Editada: Walter Roberson
el 23 de Oct. de 2021
The functions nargin and nargout will error if executed at the base. So you can use try/catch
inbase = false; try; nargin; catch ME; inbase = true; end
0 comentarios
Más respuestas (1)
Image Analyst
el 23 de Oct. de 2021
Editada: Image Analyst
el 23 de Oct. de 2021
You can call fprintf immediately upon entering and just befor leaving the function:
fprintf('Entering MyFunction().\n');
fprintf('Leaving MyFunction().\n');
If you stop at a break point, you can check the call stack on the tool bar. Or you can get the call stack from my attached function and print it out inside the function.
5 comentarios
Image Analyst
el 24 de Oct. de 2021
@Saang Bum Kim, okay. I don't see Stephen on this thread, but it looks like you've accepted the Answer from Walter so I guess everything is figured out and working now. Best wishes.
Ver también
Categorías
Más información sobre Historical Contests en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!