Check if a variable or field is used?

This feature probably doesn't exist, but I thought I'd ask. Is there a way to check if a certain variable or field in a structure is called? I'm reading through a very large existing code, and rather than trying to step line by line (which is what I'm currently doing), it would be helpful if there was a way for Matlab to tell me that some variable is called or interacted in some way.

5 Comments

If you literally just want to do a one time check can you not just rename it and run your code and see if it still works?
Moved my answer to comment (was not really an answer): Why can't you just do "ctr + f" or in the editor click on "Find" and type in the certain variable or field you are looking for?
Mark Kim's response to my answer: The code is written in such a way that it calls many other functions (a few dozen) and each function calls many structures, and those structures have function handles inside so the actual function name isn't always used when the function is called since most of the time they're called from the handle name.
In response to Adam (sorry I didn't see your comment until now), I think that's probably the best thing to try. What I am ultimately trying to do is to create my own set of data text files for the simulation to read from. Currently it reads from an existing data file, but it has many parameters that don't seem to be used at all (at least that's what it seems like after careful reading through the code). The simulation reads the data, puts it into structures, and as described in my response to Moe_2015, has structures within structures within structures and function handles all over the place so it's hard to follow the bread crumbs and determine whether a field is actually used. I'll just go ahead and run it with a test data file and see if it doesn't crash, haha.
Stephen23
Stephen23 on 1 Aug 2016
Edited: Stephen23 on 1 Aug 2016
@Mark Kim: are the fieldnames dynamically generated, ore are they hardcoded ?
I guess the obvious way to achieve your goal would be to overload the struct class, and add some functionality that displays/stores access information when the fields are accessed. (Assuming that they use some kind of get/set methods).

Sign in to comment.

Answers (0)

Categories

Asked:

on 28 Jul 2016

Edited:

on 1 Aug 2016

Community Treasure Hunt

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

Start Hunting!