I have below table in matlab an i want to aggregate this table based on column name ,
name nums
'es' '1,2,3'
'mo' '4,3,1'
'al' '2,3,1'
'es' '40,2,8'
'es' '1,2,5'
'mo' '5,2,1'
'ta' '9,4,2'
'al' '2,6,1'
...
and this my desired output:
name nums
'es' '1,2,3,8,40,5'
'mo' '4,3,1,5,2'
'al' '2,3,1,6'
'ta' '9,4,2'
...
and this is my code,
n,m = size(T);
for i = 1:n
if ~ismember(name,mynewtab)
mynewtab.input(i).nums = mynewtab.input(i).nums + nums;
else
mynewtab.input(i).nums = mynewtab.input(i).nums + nums;
mynewtab.input(i).name = name;
end
end
but this code has some errors.

댓글 수: 3

madhan ravi
madhan ravi 2018년 10월 29일
by the how did you create a table with duplicate row name , curious..
Stephan
Stephan 2018년 10월 29일
I think this are not row names, but entries in the column named 'name'.
esmaeil zahedi
esmaeil zahedi 2018년 10월 29일
Read from xlsx file

댓글을 달려면 로그인하십시오.

답변 (1개)

Peter Perkins
Peter Perkins 2018년 10월 31일

0 개 추천

I doubt that what you showed is actually what you want.
I imagine what you want is a table (the datatype) with a categorical variable Name, and a cell variable Nums, each cell of which contains a numeric vector of different lengths. From there; it's a one-liner: call varfun with @(x) unique([x{:}],'stable') as the function.
If Nums in your table is a cell array containing numeric row vectors, that function will receive a smaller cell array, all the cells corresponding to, say, ES, concatenate all the contained row vectors, and return just the unique numbers.

카테고리

도움말 센터File Exchange에서 Tables에 대해 자세히 알아보기

태그

질문:

2018년 10월 29일

답변:

2018년 10월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by