Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Comparing two matrix elements summing third and storing them separately
1 回表示 (過去 30 日間)
古いコメントを表示
the problem is extension of the question https://www.mathworks.com/matlabcentral/answers/106095-comparing-matrix-elements-and-performing-operation-if-equal
whenever the elemnts in column 1 and 3 both are repeated elsewhere in matrix then only third column should get added up
e.g
A=
18 18 1
17 20 2
18 18 1
17 25 2
19 17 3
18 18 1
19 17 3
then answer should be
18 18 1
17 20 2
18 18 2
17 25 2
19 17 3
18 18 3
19 17 6
After that i want that the final matriz should be of the form
x = [ 17 20 2
17 25 2
18 18 3
19 17 6]
0 件のコメント
回答 (2 件)
madhan ravi
2019 年 7 月 7 日
T = array2table(A);
t = groupsummary(T,{'A1','A2'},'sum');
x = t{:,[1,2,end]}
1 件のコメント
madhan ravi
2019 年 7 月 7 日
Or:
[u,~,idx] = unique(A(:,1:2),'rows');
x = [u,accumarray(idx,A(:,3),[],@sum)]
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!