Can I manually scope variables to a region of code?
In C++ I would do this:
{
int var = 1;
int var2 = 2;
// etc...
// do something with var...
}
// the variables are now out of scope
As I understand the Matlab equivalent would be
var = 1;
var2 = 2;
% etc...
% do something with var
clear var var2 etc...;
% the variables are now out of scope (well, they're deleted)
I am fond of the C++ version because it means I don't have to remember
which variables I have to delete, and it conveniently allows me to create
blocks of code that can be easily visualised (the code in the brackets
looks like one unit of code).
Does something like this exist in Matlab?
No comments:
Post a Comment