Problem Using groupsummary function

4 ビュー (過去 30 日間)
Alfredo Salinas Martinez
Alfredo Salinas Martinez 2020 年 4 月 15 日
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
  1 件のコメント
darova
darova 2020 年 4 月 15 日
What about this?

サインインしてコメントする。

採用された回答

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.
  1 件のコメント
Alfredo Salinas Martinez
Alfredo Salinas Martinez 2020 年 4 月 17 日
Thank you!
That solved it!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by