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

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.

Risposte (1)

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 Commenti

Well in a function I generated there are about 100 lines randomly scattered about the function of 1000 lines with a warning at each that the line might be unused. I am wondering if there is any way to comment out all of these specific lines without going through one by one and manually commenting them. Maybe that falls under what you meant by "code in an unused local function." I am not sure, but I am wondering if there is a way to essentially delete all of those lines at once. I have the option to suppress all the warnings but I am hoping to minimize the computational burden by just removing these unnessary calculations.
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?
Do you know the best way to leave suggestions? I have tried before but could not find an official way to do it.

Accedi per commentare.

Categorie

Scopri di più su Programming in Centro assistenza e File Exchange

Prodotti

Release

R2020b

Richiesto:

il 1 Lug 2021

Commentato:

il 29 Set 2021

Community Treasure Hunt

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

Start Hunting!

Translated by