How to extract table rows based on a column entry (string) which match a pattern?

31 ビュー (過去 30 日間)
I have table where health column contains has similar values, like '1 Hour Saline', '2 Hour Saline', '2 hour Saline', '3 Hour Saline', '4 Hour Saline'. So far I'm fetching those rows with the following code
mergedTable( == '1 Hour Saline' | ... == '2 Hour Saline' | == '2 hour Saline' | ... == '3 Hours Saline' | == '4 Hour Saline', :);
Is there an option to write the query using a pattern? I would also prefer the query to be case insensitive. I have attached the sample table for your reference.


Cris LaPierre
Cris LaPierre 2022 年 10 月 14 日
編集済み: Cris LaPierre 2022 年 10 月 14 日
You can use MATLAB's pattern matching functions (I like contains for this application). The table you shared does not contain any iteration of "Hour Saline" in it, but if it did, something like this should work.
ind = contains(, "Hour Saline");
T2 = mergedTable(ind, :)

その他の回答 (0 件)


Find more on Tables in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!

Translated by