MATLAB Answers

Simplifying an array with repeat values in it

1 view (last 30 days)
Ean Hendrickson
Ean Hendrickson on 16 Dec 2019
Answered: Akira Agata on 16 Dec 2019
I have an array with repeated values in it. I want to simply the array so there are no repeat values in column 1 while also summing the associated values in column 3. Attached is an excel spreadsheet of the inputs and outputs of what I want the array to look like. I am aware of sort, unique, and accumarray but I am having trouble putting it all together.


Sign in to comment.

Answers (1)

Akira Agata
Akira Agata on 16 Dec 2019
How about the following?
[g,tbl] = findgroups(data(:,{'partnumber','description'}));
QYT = splitapply(@sum,data.QTY,g);
tbl.QYT = QYT;
>> tbl
tbl =
4×3 table
partnumber description QYT
__________ _____________ ___
100 "resistor" 3
200 "capacitor" 3
300 "inductor" 1
400 "transformer" 8


Sign in to comment.

Sign in to answer this question.




Translated by