Indexing based on part of a string

18 ビュー (過去 30 日間)
Kristine
Kristine 2025 年 10 月 6 日 23:17
コメント済み: Kristine 2025 年 10 月 7 日 0:44
Hi y'all,
I want to pull information from a table based on two pieces of information. I want the values in column1 to be 01, and I want the values in column 2 to include the text "2025-02"
This code did not work:
No1 = table(table.column1 == 01, table.column2 == '2025-02*');
I can only get a list of the rows if I use the full text found in column2. But I want to find all of the rows where part of the text exists.

採用された回答

Paul
Paul 2025 年 10 月 6 日 23:23
column1 = [1;2;1;2;1]; column2 = ["2025-02 A";"A 2025-02";"B";"a 2025-02 a";"b 2025-02 b"];
T = table(column1,column2)
T = 5×2 table
column1 column2 _______ _____________ 1 "2025-02 A" 2 "A 2025-02" 1 "B" 2 "a 2025-02 a" 1 "b 2025-02 b"
T(T.column1 == 1 & contains(T.column2,"2025-02"),:)
ans = 2×2 table
column1 column2 _______ _____________ 1 "2025-02 A" 1 "b 2025-02 b"
  2 件のコメント
Kristine
Kristine 2025 年 10 月 7 日 0:37
I get an error:
First argument must be text
Kristine
Kristine 2025 年 10 月 7 日 0:44
Never mind. I had to change the second column to string. I didn't realise it was interpreting it as catigorical. It works now. Thanks!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by