Why the regexp returns wrong result?

1 回表示 (過去 30 日間)
Wei Sue
Wei Sue 2022 年 11 月 8 日
編集済み: Stephen23 2022 年 11 月 10 日
Hi,
I use who function and '-regexp' to help me sort data that matches my criteria.
dataList = who(subBatchData,'-regexp','^X.*2');
It works well in other data. While in this data, it returns wrong result. And in the same batch, using '^X.*4'/ '^X.*8' can also get correct results.
So, why it returns wrong answer?
  1 件のコメント
Stephen23
Stephen23 2022 年 11 月 10 日
編集済み: Stephen23 2022 年 11 月 10 日
Having lots of numbered variable names is usually a sign that something is going wrong:
The MATLAB documentation states "Avoid functions that query the state of MATLAB such as inputname, which, whos, exist(var), and dbstack. Run-time introspection is computationally expensive."
The most important question is: how did you get all of those variables into the workspace? There is probably a more robust and more efficient approach to processing this data.

サインインしてコメントする。

回答 (1 件)

Askic V
Askic V 2022 年 11 月 8 日
編集済み: Askic V 2022 年 11 月 8 日
Because you have a match, for example, for the first element:
X2300IF_S1
Did you perhaps want:
'^X.*2$'
so that 2 must be at the end?
  2 件のコメント
Wei Sue
Wei Sue 2022 年 11 月 8 日
Thank you for your answer!
I didn't realize that I forgot the `$` in the expression.
Thanks for your time again.
Askic V
Askic V 2022 年 11 月 8 日
If you are satisfied with the answer, please accept the reply as an answer to your question. Thank you.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by