Collapse logical table into cell strings that contains the table's variable names
1 回表示 (過去 30 日間)
古いコメントを表示
I have a n x m logical truth table in the format where "a b c d" are the table variable names
exampleTable =
5×4 table
a b c d
_____ _____ _____ _____
false false false false
true true true true
false false true true
true false true false
false false false true
and I would like to collapse it into a cell array of height n like below. Each row n is a cell array of strings that contains the name of the variable (column) when the entry is true
{{''}; {'a','b','c','d'}; { 'c','d'}; { 'a','c'}; {'c'}}
I imagine I can do something with cellfun, but I'm a little stuck. Thanks for your help!
0 件のコメント
採用された回答
Walter Roberson
2022 年 1 月 6 日
temp = [ false false false false
true true true true
false false true true
true false true false
false false false true ];
exampleTable = array2table(temp, 'VariableNames', {'a', 'b', 'c', 'd'})
varnames = exampleTable.Properties.VariableNames;
output = rowfun(@(r) varnames(r), exampleTable, 'SeparateInputs', false, 'OutputFormat', 'cell')
output{2}
3 件のコメント
Walter Roberson
2022 年 1 月 6 日
If you need to do those kinds of queries, you are better off sticking with the original representation.
mask = exampleTable.a | exampleTable.c
or even
mask = any(exampleTable{:,{'a', 'c'}},2);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!