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));

回答(2 个)

Yongjian Feng
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.
  1 个评论
Qiana Curcuru
Qiana Curcuru 2021-7-20
I think what im looking for is a command that can tell me which items in the matrix are cells so i can figure out how to make them compatible

请先登录,再进行评论。


Walter Roberson
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));

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by