Simplifying an array with repeat values in it

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.

답변 (1개)

Akira Agata
Akira Agata 2019년 12월 16일

0 개 추천

How about the following?
load('data.mat');
[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

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

릴리스

R2015b

질문:

2019년 12월 16일

답변:

2019년 12월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by