When I use 'varfun' with a grouping variable that contains empty char row vectors (''), the resulting table excludes these rows. See the following example:
 
tblInput = table({'';'';''},[10;20;30],[40;50;60],[7, 1;8, 2;9,3]);
tblInput.Properties.VariableNames = {'X','Y','Z','Quantity'};
strGroupingVariables = {'X','Y','Z'};
tblEmpty = varfun(@nansum,tblInput,'GroupingVariables',strGroupingVariables, 'InputVariables', {'Quantity'})
result:
tblEmpty =
  0×5 empty table
Is this expected behavior? How do I get the resulting table to include the columns of 'X', just as an empty string?

 채택된 답변

MathWorks Support Team
MathWorks Support Team 2018년 2월 2일

0 개 추천

The behavior you are experiencing is expected behavior. When creating a column consisting of a cell array with empty strings, these are actually treated as empty char row vectors rather than empty strings. Since these are treated as empty char row vectors, they are treated as a missing value. Because of this, there is no "group" to assign them to when passing the variable 'X' to the 'GroupingVariables' parameter, so the entire row is excluded. 
A workaround would be to convert the variable 'X' from a cell array to a string array, as follows:
 
tblInput = table({'';'';''},[10;20;30],[40;50;60],[7, 1;8, 2;9,3]);
tblInput.Properties.VariableNames = {'X','Y','Z','Quantity'};
tblInput.X = string(tblInput.X);
strGroupingVariables = {'X','Y','Z'};
tblEmpty = varfun(@nansum,tblInput,'GroupingVariables',strGroupingVariables, 'InputVariables', {'Quantity'})
result:
tblEmpty =
3×5 table
X Y Z GroupCount nansum_Quantity
__ __ __ __________ _______________
"" 10 40 1 8
"" 20 50 1 10
"" 30 60 1 12

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

제품

릴리스

R2017b

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by