findgroups error class variable not supported
6 次查看(过去 30 天)
显示 更早的评论
I have a cell array, 'finalData'' and trying to use the findgroups command to sort it but i keep getting the error:
I dont have any cells in 'finalData' that appear to be cells. is there an easy way to trouble shoot?
Error using matlab.internal.math.grp2idx (line 125)
A grouping variable of class 'cell' is not supported.
Error in matlab.internal.math.mgrp2idx (line 64)
[ogroup,gnum,gdata{1}] = matlab.internal.math.grp2idx(group{1,1},inclnan,inclempty);
Error in findgroups (line 88)
[gnums,~,gnames] = matlab.internal.math.mgrp2idx(groupVars,0,inclnan,inclempty);
Error in STK_LEO_OP (line 185)
[G, fields] = findgroups(finalData(:,1));
0 个评论
回答(2 个)
Yongjian Feng
2021-7-20
You can type help findgroups from command line window. It show what input argument findgroups is expecting:
G = findgroups(A) returns G, a vector of group numbers created from the
grouping variable A. G contains integer values from 1 to N, indicating
N distinct groups for the N unique values in A.
A is a categorical, numeric, logical, string, datetime, duration,
or calendarDuration vector, or a cell array of character vectors.
G has the same length as A.
Any other kind of A can generate an error you saw.
Walter Roberson
2021-7-20
I have a cell array, 'finalData''
[G, fields] = findgroups(finalData(:,1));
When you use () indexing with a cell array, the result is a cell array. You might need to
[G, fields] = findgroups(finalData{:,1});
However, if you have multiple entries in the cell, then a question arises as to whether you want to find the groups over all of the entries, or if instead you want to find groups per-entry. If you want to find groups per-entry then
[G_cell, fields_cell] = cellfun(@findgroups, finalData(:,1));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!