How do I search my workspace variables?
Show older comments
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
James Tursa
on 17 Jan 2018
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
on 17 Jan 2018
Edited: alex george
on 17 Jan 2018
Stephen23
on 17 Jan 2018
"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
on 17 Jan 2018
Edited: alex george
on 17 Jan 2018
Stephen23
on 17 Jan 2018
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.
Walter Roberson
on 17 Jan 2018
For example,
whos starting*
alex george
on 17 Jan 2018
Greg
on 18 Jan 2018
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.
Answers (0)
Categories
Find more on Environment and Settings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!