Problem Using groupsummary function

4 次查看(过去 30 天)
Hi, I'm trying to count how many times a coordinate (x,y) repeats in a file. I'm using this code:
SBc='sb-noH_2R401_Coord.gtxt'; % Nombre del archivo a abrir
SBIDc = fopen(SBc); % Abre el archivo
cell = textscan(SBIDc,' % f %f'); %Escanea la información del archivo y la almacena en una 'célula'.
fclose(SBIDc);
mc=cell2mat(cell); % convierte la celula en matriz
table1=table(mc(:,1)); % convierte a tabla la info
table2=table(mc(:,2));
zt=table(table1,table2,'VariableNames',{'xc','yc'});
count=groupsummary(zt,{'xc','yc'})
And, I'm getting this error:
Error using matlab.internal.math.grp2idx (line 172)
A grouping variable of class 'table' is not supported.
Error in matlab.internal.math.mgrp2idx (line 93)
[g,countgrp(j),gd{1,j}] = matlab.internal.math.grp2idx(group{1,j},inclnan,inclempty);
Error in groupsummary (line 385)
[gvidx,numgroups,gdata,gcount] = matlab.internal.math.mgrp2idx(groupingdata,size(T,1),inclnan,inclempty);
Any idea what I'm doing wrong?
I did all this once and I got it right, now I don't understand why it's not working
Thank you

采纳的回答

Adam Danz
Adam Danz 2020-4-15
编辑:Adam Danz 2020-4-17
The error message tells you the problem:
A grouping variable of class 'table' is not supported.
This line,
zt=table(table1,table2,'VariableNames',{'xc','yc'});
combines two tables. zt.xc is a table within the zt table. Same with zt.yc.
The grouping variable cannot be a table.
If table1 and table2 are tables with a single column and an equal number of rows, you can combine them horizontally like this.
zt = [table1, table2];
You can change the variable names before or after combing the table columns.
If those tables do not have single columns, you can continue with your current method but you'll need to specify the grouping column differently.

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by