using accumarray to combine text
2 views (last 30 days)
Show older comments
Hi,
I am trying to use accumarray to concatenate string.
tdata = table([ 1 2 2 3 4 2]', ["a","b","c","d","e","f"]', 'VariableNames',{'EBID','Name'});
[uniqEBID,~,JGrp] = unique( tdata(:, {'EBID'}));
joinStr = @(tStr) { sprintf([repmat('%s|| ', 1, length( tStr)-1) '%s'], string( tStr))};
joinStr( tdata.Name) % anonymous function seems to do the job
However when running script below, i got error message
accumarray( JGrp, tdata.Name, [], joinStr)
Error using accumarray
Second input VAL must be a full numeric, logical, or char vector or scalar.
Accepted Answer
Stephen23
on 22 Aug 2022
T = table([1;2;2;3;4;2], ["a";"b";"c";"d";"e";"f"], 'VariableNames',{'EBID','Name'})
G = findgroups(T.EBID);
F = @(s)join(s,"||");
S = splitapply(F,T.Name,G)
0 Comments
More Answers (1)
Voss
on 26 Jan 2022
Does this do what you want?
tdata = table([ 1 2 2 3 4 2]', ["a","b","c","d","e","f"]', 'VariableNames',{'EBID','Name'});
[uniqEBID,~,JGrp] = unique( tdata(:, {'EBID'}));
joinStr = @(tStr) { sprintf([repmat('%s|| ', 1, length( tStr)-1) '%s'], string( tStr))};
% joinStr( tdata.Name) % anonymous function seems to do the job
joinStr( tdata.Name(JGrp))
0 Comments
See Also
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!