Is it possible to load a variable that can not be cleared
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a variable 'x' that is loaded using the startup file in ...\Documents\MATLAB\startup.m that executes the command
load x
I want this variable to remain in the workspace after executing
clear
in any of my MATLAB scripts or functions. Is this possible?
1 comentario
Walter Roberson
el 12 de Jul. de 2019
Which workspace does it need to stay in? Do any of the scripts need to execute at the command prompt, or are they all called within functions? Does the variable need to survive "clear all"?
Respuestas (2)
Walter Roberson
el 13 de Jul. de 2019
Create a function named X.m that when given the argument 'load' loads the value of X from a file and puts it into a persistent variable and uses mlock
https://www.mathworks.com/help/matlab/ref/mlock.html
For any other argument, including no argument, index the persistent variable and return that result.
Limitations:
- does not permit the user to store into the variable
- does not permit use of end as an index
You can possibly improve on this by defining an object with subsref and subsasgn behavior.
You cannot simply mlock a variable however.
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!