findgroups error class variable not supported

9 visualizzazioni (ultimi 30 giorni)
Qiana Curcuru
Qiana Curcuru il 20 Lug 2021
Risposto: Walter Roberson il 20 Lug 2021
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));

Risposte (2)

Yongjian Feng
Yongjian Feng il 20 Lug 2021
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 Commento
Qiana Curcuru
Qiana Curcuru il 20 Lug 2021
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

Accedi per commentare.


Walter Roberson
Walter Roberson il 20 Lug 2021
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));

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Prodotti


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by