- Use functions, not scripts. Each function should have documentation explaining the purpose, inputs, and outputs. That way you don't have to worry about implementation details, which will also allow you to update code without worrying about whether the variables you're using might affect other scripts.
- If you have a function that sets a lot of default values, let it return a struct. That way it is also clear where values come from.
- You might want to consider changing your PLOT_STANDARDS to a class. That way you can import all default values the same way as a struct, but if you want to change settings you can have methods that check whether the new combination of settings is possible. In a way you can think of a class as a smart struct.
- Don't use clear,clc,close all. It is an example of cargo cult programming and a code smell.
Including external file is making workspace messy
2 views (last 30 days)
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.
Rik on 8 Oct 2021
Let me expand on the suggestion of @Mathieu NOE: