MATLAB: Syntax to comment/uncomment line(s) of code in a Matlab script

skip linesuncomment

I am writing a code for a class project. It requires me to do same calculations for two different cases based on user input. I was going to code it in a way that the program would ask user which case to follow. However, I found out that because of various parameters related to each other, this will be extremely difficult. However, I thought of another way to do this but I don't know if I could do it in Matlab. So the way I want to code is, I would ask the user to choose one of the two cases, and based on his input, I would comment or uncomment OR read or skip a bunch of lines or line numbers. Is this possible to do in a running Matlab script? I know how to comment/uncomment a line in a Matlab script that's not running, but I was wondering if there is a syntax to skip reading certain lines in a running Matlab script.

Best Answer

There is no way (at least as far as I am aware) to comment out lines programatically. However, even if you could, this is almost certainly not a good approach for what you are trying to do.
Instead, I think the easiest way is just to wrap it in an if statement
if (user_input_condition_1)
%code to run for case 1
else
%code to run for case 2
end
You can also use switch statements instead of the if statements--the approach is similar.
Related Question