can i somehow get the connections and dependencies involving several scripts ?

6 views (last 30 days)
hi,
i have a skript in my hands, that uses of around 50 selfmade functions. my problem is, that many of them have near a dozen inputs as well as outputs, which makes it real hard to track something down or so. i wondered if there is something, that shows me all the functions, and the dependencies, also the inputs, where they come from and where the outputs go to.
now i do know about projects, but as far as i have seen it, i can only make the dependencies visible, not the outputs and inputs.
thanks in advance for any advice :D
  5 Comments
Harald
Harald on 15 Nov 2023
Hi Andre,
those already are all structs or tables
Structs are hierarchical in the sense that the fields of a struct can again contain a struct, a table... actually anything. Thus if you find the same set of structs / tables being used repeatedly, combining these into a struct (or object) may help.
the only thing wleft would be an object oriented approach, which i do lack the skills of. i just cant get it into my head xD
I may be able to help with that. :) There is the free self-paced Object-Oriented Programming Onramp which gives a first introduction to object-oriented programming with MATLAB and may already help with some concepts. Beyond that, there is a 2-day instructor-led training offering Object-Oriented Programming with MATLAB. I am actually one of the instructors who deliver this training, so we might see each other there. :)
Best wishes,
Harald
Andre
Andre on 16 Nov 2023
Hi Harald,
the structs being used contain all the values that makes sense in that case. bundle them up further would only obstruct whats actually given to that function. this would also make it harder for me, to know what the actual inputs and outputs are. now i have "one layered" structs, having more layers to it would make it near impossible for me to know whats going in and whats going out.
anyways, i think that there is no such thing somewhere to know what i want.

Sign in to comment.

Answers (1)

Yatharth
Yatharth on 3 Jan 2024
Hi Andre,
I understand that you're dealing with a complex codebase with many interdependent functions, and you're looking for ways to better understand the flow of data through these functions.
While there might not be a one step solution but I have few recommendations.
  1. Using Dependency Analyzer: The Dependency Analyzer app is an interactive tool for visualizing and analyzing dependencies among files.Refer to the following links to know more about Dependency Analyzer and how to explore the Dependency Graph. https://www.mathworks.com/help/matlab/matlab_prog/analyze-project-dependencies.html#mw_34458c68-8e31-477b-a142-bda90c94f492
  2. Refactoring: It may be beneficial to refactor your functions to reduce the number of inputs and outputs. Consider grouping related parameters into structures or using objects if it's suitable for your application. This can greatly simplify the function interfaces and make the code easier to follow.
  3. Function Signatures: Use descriptive variable names for inputs and outputs to make the code self-documenting. This makes it easier to infer where a variable is coming from and what it represents.
  4. Documentation: Make sure each function is well documented, specifying what each input and output is. This can be done using the “%” comment syntax at the beginning of each function. MATLAB's “help” and “doc” commands can then be used to quickly get an overview of what a function does without having to read the code in detail.
Below is an example of how you might document a function with multiple inputs and outputs with a well-defined function signature for a hypothetical function that calculates the area and circumference of a circle given its radius:
function [area, circumference] = calculateCircleMetrics(radius)
%CALCULATECIRCLEMETRICS Calculate the area and circumference of a circle
% [area, circumference] = calculateCircleMetrics(radius) returns the
% area and circumference of a circle given its radius.
%
% Input:
% radius - A scalar representing the radius of the circle (non-negative)
%
% Outputs:
% area - The area of the circle
% circumference - The circumference of the circle
%
% Example:
% [a, c] = calculateCircleMetrics(5);
% fprintf('Area: %.2f, Circumference: %.2f\n', a, c);
% Calculate the area
area = pi * radius^2;
% Calculate the circumference
circumference = 2 * pi * radius;
end
You can use "help calculateCircleMetrics" in the command window to get an overview for a function.
Regularly refactoring, documenting, and testing your code can make it much more manageable over time. Should you notice a recurring challenge in maintaining a clear understanding of the data flow within your functions, it may be indicative of an opportunity to consider restructuring your code. By doing so, you can achieve a more modular and maintainable design, which will greatly benefit both the current usability and future adaptability of your work.
I hope this helps!

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!