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

조회 수: 96 (최근 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(mergedTable.health == '1 Hour Saline' | ...
mergedTable.health == '2 Hour Saline' | mergedTable.health == '2 hour Saline' | ...
mergedTable.health == '3 Hours Saline' | mergedTable.health == '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(mergedTable.health, "Hour Saline");
T2 = mergedTable(ind, :)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by