Storing workspace variables that match the specified regular expressions.

11 vues (au cours des 30 derniers jours)
How do we store workspace variables identifed using regular expressions.
Consider the following example below...
ex_1 = 5;
ex_2 = 3;
i_i = 4;
%if I do this
whos -regexp ^ex_[1]*|^i.\d+
Name Size Bytes Class Attributes ex_1 1x1 8 double ex_2 1x1 8 double
%it works
%but if I do this
s = whos(-regexp ^ex_[1]*|^i.\d+);
Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.
%it throws an error
  1 commentaire
Stephen23
Stephen23 le 7 Juin 2022
"It throws an error"
Note that storing meta-data in variable names makes code slow, complex, inefficient, buggy, and difficult to debug.

Connectez-vous pour commenter.

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 7 Juin 2022
Modifié(e) : Fangjun Jiang le 7 Juin 2022
see "doc whos"
s=whos('-regexp','^ex_[1]*|^i.\d+')

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by