
Problem Using groupsummary function
조회 수: 5 (최근 30일)
이전 댓글 표시
Alfredo Salinas Martinez
2020년 4월 15일
댓글: Alfredo Salinas Martinez
2020년 4월 17일
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
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 Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!