How can I find where a specific variable was declared?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to debug a very complex matlab code mixed with simulink models (legacy). It has nearly 1300 variables that are declared and not used by simulink anymore (I'm sure they were used before, but the model evolved and the old code parts were never erased, it just kept increasing). I managed to get a list of those variables with Simulink.findvars but I wanted to see where they are declared so I can erase them and reduce the giant workpace (this code really needs cleaning). I tried @ImageAnalyst, @StephenCobeldick and @JohnD'Errico suggestion of using
dbstop in file if expression
I declared all variables as Inf before running the root/main script that calls all the others (a value that I know any of them takes as they are all constants and only declared once). The idea would be for the simulation to stop whenever one of the variables changed value (was declared), but this doesn't work for me.
At first I thought it was due to the "in file" not considering the called scripts in the root script, only the file itself, so I did several of those lines one for each file path, by tracing all the paths of dependent scripts it calls from this solution by @ImageAnalyst.
This also didn't work as when I would enter functions the workspace would "lose" the declared variables and count them as non existent (therefore different from Inf), stopping the simulation. I also tried deffining them all as global but nothing seems to work.
Does anyone have creative ideas of how to do this? I need a file with all the paths of the scripts where the non used variables are declared, so I can go and erase them (or further develop a script to do this, since they are nearly 1300).
I know this is a problem of poor code design, but again it is legacy code...
Thanks!
1 commentaire
Steven Lord
le 16 Nov 2020
Is your MATLAB code one very large script file, a collection of medium to large script files, one very large function, a collection of functions, or some combination of scripts and functions?
Roughly how many lines long (10k, 100k, 1m, etc.) is your legacy code base? Roughly how many files?
Réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Environment Customization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!