Can create new environment (like new.env() in R) in MATLAB?
4 views (last 30 days)
Show older comments
In R, you can create new environment by
.new_env = new.env()
Can we do something similar in MATLAB?
I am trying to build different calculation environments so that I can run different m-scripts and save workspace in each environment sequentially.
6 Comments
Stephen23
on 6 Jun 2021
Edited: Stephen23
on 6 Jun 2021
"If I did not include 'clc, clear' in program1 and program 2, this code will work, but I would like to include them at the beginning."
MATLAB does not have named environments like R. MATLAB scopes variables and functions by their location: https://www.mathworks.com/help/matlab/scope-variables-and-generate-names.html
Rather than writing scripts with very smelly and anti-pattern code, the best solution by far is to use functions.
Right now you have a simple choice:
- spend quite a lot of your own time by continuing to use scripts (ugh), fighting MATLAB by adding CLEAR (ugh ugh) at the top of every script you write, and hoping for some magical way of telling MATLAB to not do exactly what you just told it to do: https://en.wikipedia.org/wiki/XY_problem https://xyproblem.info
- use functions.
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!