How do I search my workspace variables?

I have a large number of workspace variables. How can I search them for the ones I need? E.g. find my text "startingSpeed"

8 Comments

What do you mean? Find the text "startingSpeed" inside of the string or char variables that you have in the workspace? Or find variables with that text in their name? Or ...?
alex george
alex george on 17 Jan 2018
Edited: alex george on 17 Jan 2018
There's hundreds of variables in the righthand side where the workspace resides. How do I find the workspace variable with a name such as startingSpeed other than manually scrolling through to find it.
"I have a large number of workspace variables. How can I search them..."
These are not indicators of good code. Some beginners force themselves into writing slow, complex, buggy code by filling the workspace with variables and trying to magically access them.
You would be much better off avoiding such slow and obfuscated way of accessing data, and especially any that rely on runtime introspection such as searching the entire workspace.
alex george
alex george on 17 Jan 2018
Edited: alex george on 17 Jan 2018
The variables are the result of running an extremely large Simulink program. I did not write that code. Is there no way to search for a matching variable in the workspace? These "variables" contain structures and arrays for the most part.
We just warned you against doing it because it is slow (and unavoidably leads to other problems): "Avoid functions that query the state of MATLAB such as inputname, which, whos, exist(var), and dbstack. Run-time introspection is computationally expensive."
Sadly the designers of Simulink did not follow good MATLAB practice, but yes there are ways:
You need to look at who, whos, and exist.
Thanks for the help Stephen!
Assuming your end goal is to view them in the variable editor:
openvar('startingSpeed');
This won't help you find them (tab completion doesn't work inside the single-quote), but it saves scrolling the workspace and double-clicking. Also,
openvar('someVarThatDoesNotExist')
simply creates a tab in the variable editor with one short message: The variable someVarThatDoesNotExist does not exist.

Sign in to comment.

Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Tags

Asked:

on 17 Jan 2018

Commented:

on 18 Jan 2018

Community Treasure Hunt

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

Start Hunting!