Arrange the array to give the added output in other array
1 次查看(过去 30 天)
显示 更早的评论
In the following array B contains the individual results for the elements in A
Let's say,
A=[2 1 4 2 8 4 1 7 2].';
B=[1 2 3 4 5 6 7 8 9].';
Now, I want A in such a way that It only contains the the unique elements in it, like final A should be:
A=[1 2 4 7 8];
And in final B it contains the total addition of the each individual values of elements in A, so final B will look like:
B=[9 14 9 5 8];
I am looking for a simple code to execute this, it is urgent
0 个评论
采纳的回答
Stephen23
2022-4-22
A = [2;1;4;2;8;4;1;7;2];
B = [1;2;3;4;5;6;7;8;9];
[X,Y,Z] = unique(A);
N = accumarray(Z,B)
display(X)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!