Including external file is making workspace messy
Show older comments
I have created a file named PLOT_STANDARDS.m put it in a folder and added that to path to include it in other files.
But when I include that file at the start of another script in the following manner:
%=================script begins here
clear; clc; close all;
% at the very beginning itself I include my file
PLOT_STANDARDS % this has lots of variables defined for easy access in any other script
%=============
% rest of the script goes here
My file PLOT_STANDARDS has a lot of variables which I have created to use as my defaults.
But including it in the above manner brings all those to the current workspace. This is very problematic as now I cannot find the variables of the current script easily. They get lost in the huge pile of variables that are imported from PLOT_STANDARDS.
I do not want to import specific variables from PLOT_STANDARDS instead I want to use any of the variable defined in there at will.
How to include PLOT_STANDARDS or access the variables in it in such a way that does not fill my workspace.
3 Comments
Mathieu NOE
on 8 Oct 2021
hi
I would suggest you create a structure with all PLOT_STANDARDS variables inside
then when you run your script it will load only one variable => this structure
you can access any indiidual variable from within this single structure
atharva aalok
on 8 Oct 2021
Rik
on 8 Oct 2021
You don't need to save your variables in a mat file, just store them in a struct. By having it be the output of your function you can even store it to a variable with a very short name. Typing s.var is not much more of a problem than typing var. Added bonus is that it is clear whether you are working with the loaded default or with a local copy.
Accepted Answer
More Answers (0)
Categories
Find more on Scope Variables and Generate Names 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!