Tips for organizing variables in the workspace? Is there an option like "exlude capitalized variables" like python/spyder?

12 views (last 30 days)
My script has a lot of variables. Many of these are created simply to make the code easier to debug so I don't have to chase endless delimiters. However this fills the workspace variables I don't actually care about and it's kind of a disaster to search through.
Introduction/Motivation
Here's a silly example that uses extraneous variables because it makes it easier to debug.
X0 = 0
Span = 5
Xorig = X0:x0+Span
x= Xorig + 3.3
y = x.^2; %easy to read what's going on in each line, but I don't really care about x0, span, xORIG etc
Here's a version that uses as few variables as possible but is slightly messier to debug.
x = 0+3.3:0+5+3.3
y = x.^2
This version slightly harder to read but has the advantage of not storing "X0", "Span", and "Xorig" as variables and cluttering the workspace.
Question
In Python/Spyder, it seems to be possible to choose exclude upper case variables from the variable explorer (see the answer to this question). A feature like this would be very nice in MATLAB but I have been unable to find one. Do people have recommendations for organizing the workspace in Matlab so it's less of a mess?
Screenshot from Anaconda Spyder:

Answers (2)

Walter Roberson
Walter Roberson on 4 Aug 2021
The below code, when executed, creates a list of links, one for each lower-case variable name. When clicked, the variable will be opened in the variable browser.
The code could be enhanced to output a certain number per line, or a maximum length per line, which would probably be a good idea; this gives a framework that could be worked with.
abc = "hello";
X42 = 7;
def = [1 2 3];
LLV
function LLV
UVN = evalin('caller', "who('-regexp', '^[a-z]')");
UVNS = string(UVN);
fprintf('%s\n', "<a href=""matlab:openvar('" + UVNS + "')"">" + UVNS + "</a>")
end

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 4 Aug 2021

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!