"contains" with multiple conditions
Version 1.1.5 (2,33 ko) par
Yasir
Returns logical true for the elements of a string array that contain a set of substrings combined by boolean operators.
Function based on MATLAB's "contains" which gives logical indices of string array "str" as true for the elements that contain a set of strings in "substr". The strings in "substr" can be combined by using EQUAL ('='), NOT ('~'), AND ('&'), OR ('|') operators processed in this order. If "substr" consists of multiple elements, they are combined by OR.
INPUTS:
"str" / "substr": string array or cell array of strings
OUTPUTS:
"idc_log": logical (TF) indices vector same length as "str"
EXAMPLE:
str = {'fuel', 'air', 'm_fuel', 'm_steam', 'Tsteam', 'Tair', 'Tfuel'};
substr = ['=Tair | ~steam | T & fuel & ~steam'];
substr = {'=Tair', '~steam', 'T & fuel & ~steam'}; % treated same as substr above
idc_log = contains_multi(str, substr)
idc_log gives indices of the elements in "str" which are exactly EQUAL to 'Tair' OR does not contain 'steam' OR contain 'T' AND 'fuel' but NOT 'steam'.
Version: 1.1
Tested on MATLAB 2020b
Yasir, 2023-11-11
Citation pour cette source
Yasir (2024). "contains" with multiple conditions (https://www.mathworks.com/matlabcentral/fileexchange/154925-contains-with-multiple-conditions), MATLAB Central File Exchange. Extrait(e) le .
Compatibilité avec les versions de MATLAB
Créé avec
R2020b
Compatible avec les versions R2020b et ultérieures
Plateformes compatibles
Windows macOS LinuxTags
Remerciements
Inspiré par : String Toolkits, structfind, mgrep, strfind for datasets
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Découvrir Live Editor
Créez des scripts avec du code, des résultats et du texte formaté dans un même document exécutable.
Version | Publié le | Notes de version | |
---|---|---|---|
1.1.5 | Changed title. |
||
1.1.4 | Renamed. |
||
1.1.3 | Renamed. |
||
1.1.2 | Renamed. |
||
1.1.1 | Accepts "susbtring" as an array of multiple strings. Individual strings will be combined by the OR operator. |
||
1.1.0 |