findgroups error class variable not supported

6 ビュー (過去 30 日間)
Qiana Curcuru
Qiana Curcuru 2021 年 7 月 20 日
回答済み: Walter Roberson 2021 年 7 月 20 日
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 Center および File ExchangeData Type Conversion についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by