Subset Table using an array of strings
조회 수: 7 (최근 30일)
이전 댓글 표시
I am using the following code to select a subset of my table based on column names:
table_subset = table(:,ismember(table.Properties.VariableNames, {'col1' 'col2'}));
However, I would like to provide the cell input based on an existing array of column names, like so:
list_of_cols = ['col1' 'col2']
table_subset = table(:,ismember(table.Properties.VariableNames, list_of_cols));
But I am getting an empty table.
댓글 수: 0
답변 (1개)
Dave B
2021년 11월 12일
편집: Dave B
2021년 11월 12일
I think you want
list_of_cols = {'col1' 'col2'}
or
list_of_cols = ["col1" "col2"]
because list_of_cols as you wrote it evaluates to the wrong thing:
list_of_cols = ['col1' 'col2']
Here's a quick test:
t=table(1,2,3);
list_of_cols = {'Var1' 'Var3'};
t(:,ismember(t.Properties.VariableNames,list_of_cols))
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!