findgroups error class variable not supported

조회 수: 8 (최근 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 CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by