How to generate a diagram illustrating the relationship between several nested functions?

조회 수: 6 (최근 30일)
I have been working with someone else's code that is quite long and full of nested functions and if conditions. I am interested in outputting some variables that are created within a nested function, that is within another nested function, that is within an if condition, etc... It is looking a little like a maze.
I was wondering if there are any ways or tools to automatically generate a diagram that illustrates how nested functions are used within a code. Something sort of like the class diagram viewer tool. Or if you have another suggestion on how to map this, I'd highly appreciate it too.
Thanks in advance!

답변 (1개)

John D'Errico
John D'Errico 2023년 3월 1일
You are asking for what is essentially a high level flow chart, produced automatically from existing MATLAB code, that shows how functions are called, the interactions of if statements, etc.
Unfortunately, there is no such automatic tool, and writing one would be a bit of a headache, certainly so for some codes if the author was determined to write bad code. For example, suppose I wrote code that used eval to create the name of a function and then call it on the fly? UGH. Yes, that would be an obscenity, but I probably know someone who would write that way.
Perhaps you might be able to use the profiler tool as something in the right direction. It would require you to run the code, fully exercising the various pathways that could be taken in the code. But if you could do that, then you would probably already know enough about the code that you would not need the required flow chart.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by