Can create new environment (like new.env() in R) in MATLAB?

4 visualizaciones (últimos 30 días)
Roy0014
Roy0014 el 3 de Jun. de 2021
Comentada: Roy0014 el 6 de Jun. de 2021
In R, you can create new environment by
.new_env = new.env()
as shown in here .
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 comentarios
Stephen23
Stephen23 el 6 de Jun. de 2021
Editada: Stephen23 el 6 de Jun. de 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:
  1. 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
  2. use functions.
Roy0014
Roy0014 el 6 de Jun. de 2021
Yes, you are right. I should use function in this case. Thank you very much for your reply.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by