필터 지우기
필터 지우기

How to select multiple contain conditions in a table?

조회 수: 11 (최근 30일)
Joy Shen
Joy Shen 2023년 6월 13일
이동: Stephen23 2023년 6월 14일
Hi, I'm basically trying to filter my results to remove irrelevant rows based on two string conditions. I've attached the xslx file. I need to know the specific cause when the operating mode is 'critical' and the LOOP category is 'WR'. Basically isolating all the rows in the table where my two conditions are met.
Data = readtable('LOOP Events.xlsx','Range','D2:K370'); % Load excel from specified sheet
%LOOPS = cat(2,Data(:,1),Data(:,2),Data(:,3));
LOOPS = cat(2,table2array(Data(:,1)),table2array(Data(:,7)));%,table2array(Data(:,8)));
LOOPS = LOOPS(~all(cellfun(@isempty,LOOPS),2),:);
substr = {'Critical','SEE','EEE'};
selectedcol = contains(LOOPS,substr);
Cause = Data(:,3);
Select_Cause= Cause(selectedcol,:)

채택된 답변

Stephen23
Stephen23 2023년 6월 13일
편집: Stephen23 2023년 6월 13일
The MATLAB approach:
T = readtable('LOOP Events.xlsx','Range','D:K');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
T = rmmissing(T) % remove empty rows
T = 186×8 table
OperatingMode LOOPCategory LOOPClass SwitchyardRestorationTime PotentialBusRecoveryTime ActualBusRestorationTime Cause SpecificCause _____________ ____________ ______________ _________________________ ________________________ ________________________ _________ _______________ {'Critical'} {'SC'} {'LOOP-IE-I' } 15 28 28 {'HES' } {'Maintenance'} {'Critical'} {'SC'} {'LOOP-IE-I' } 0 4 4 {'Equip'} {'Breaker' } {'Shutdown'} {'SC'} {'LOOP-SD' } 15 28 28 {'HES' } {'Maintenance'} {'Shutdown'} {'SC'} {'LOOP-SD' } 77 82 82 {'Equip'} {'Other' } {'Shutdown'} {'SC'} {'LOOP-SD' } 62 63 63 {'Equip'} {'Transformer'} {'Critical'} {'SC'} {'LOOP-IE-I' } 95 118 213 {'Equip'} {'Breaker' } {'Shutdown'} {'WR'} {'LOOP-SD' } 528 533 533 {'SEE' } {'High Winds' } {'Critical'} {'SC'} {'LOOP-IE-I' } 1 2 3097 {'Equip'} {'Relay' } {'Critical'} {'WR'} {'LOOP-IE-I' } 1 16 7414 {'EEE' } {'Tornado' } {'Critical'} {'WR'} {'LOOP-IE-I' } 1 16 7414 {'EEE' } {'Tornado' } {'Shutdown'} {'SC'} {'LOOP-SD' } 39 44 44 {'Equip'} {'Transformer'} {'Critical'} {'WR'} {'LOOP-IE-I' } 1 16 7414 {'EEE' } {'Tornado' } {'Critical'} {'SC'} {'LOOP-IE-I' } 86 91 101 {'Equip'} {'Relay' } {'Critical'} {'PC'} {'LOOP-IE-NC'} 60 62 781 {'HE' } {'Switching' } {'Shutdown'} {'WR'} {'LOOP-SD' } 1120 1125 1508 {'SEE' } {'Salt Spray' } {'Shutdown'} {'SC'} {'LOOP-SD' } 15 30 136 {'HES' } {'Testing' }
X = matches(T.OperatingMode,'Critical') & matches(T.Cause,{'SEE','HEE'});
Select_Cause = T.LOOPClass(X)
Select_Cause = 19×1 cell array
{'LOOP-IE-NC'} {'LOOP-IE-NC'} {'LOOP-IE-NC'} {'LOOP-IE-NC'} {'LOOP-IE-NC'} {'LOOP-IE-I' } {'LOOP-IE-NC'} {'LOOP-IE-NC'} {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' } {'LOOP-IE-I' }

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by