Is there a way to comment out all unused lines in an automatically generated code at once?

15 vues (au cours des 30 derniers jours)
Nick
Nick le 1 Juil 2021
Commenté : Bon il y a environ 12 heures
I am using matlabFunction to automatically generate very large symbolic functions. In the generated function, there are a number of lines out of a few thousand that are ununsed. Plus, sometimes I have to do some manipulation to the generated fuction that can leave hundreds of lines unused. I am wondering if there is a way to comment out all unused lines at once so that computational burden can be reduced by skipping calculations that are unused. Thanks.
  1 commentaire
Bon
Bon il y a environ 8 heures
Paul a ajouté un drapeau à commentaire
@Geometry Dash I don't think there’s a built-in way to automatically comment out unused lines, but you might try using MATLAB's code analyzer or a quick script that parses variable dependencies and removes (or comments) the ones that aren't referenced. It would definitely make debugging and performance checks easier.

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 1 Juil 2021
You can use the block comment operators to comment out a section of code, or you could select the lines and use either the button on the Toolstrip or the keyboard shortcuts. See this documentation page for more information.
If you're looking for something that can "automatically figure out if lines are unused" the answer is no, not really, except in certain special circumstances (code that immediately follows a return statement, for example, or code in an unused local function.)
  3 commentaires
Valeri Aronov
Valeri Aronov le 29 Sep 2021
This has to be a suggestion for the coming releases. Considering MATLAB detects unused lines it is just a matter of removing these lines in the code generated by matlabFunction(). Do I leave it to Nicholas to suggest?
Nick
Nick le 29 Sep 2021
Do you know the best way to leave suggestions? I have tried before but could not find an official way to do it.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by