Cumalative sum of each row of the matrix and the matrix array, separately
1 次查看(过去 30 天)
显示 更早的评论
Hi, given the following matrix and matrix array
G= {[1 2 1 2 1 1 1 2 3 4 4 5 4 5 5 4 4 5 5 4 5 4 5 4 5 4 6 6 6 6 6 6 3 3 9 9 3 9 6 9 6 9 3 9 9 9 6 3 3 6 9 3],[ 2 3 2 2 3 2 4 5 3 3 4 4 4 5 5 4 4 5 5 3 4 6 3 6 5 3 6 3 3 4 6 6 3 6 3 3 9 3 9 9 6 9 9 3 6 9 9 3 9 9 9 6 3 9]};
M = [18.7881862745098 30.3150000000000 73.4958823529412 24.6001470588235 38.4521568627451 2.01073529411765 62.1730392156863 45.2583823529412 6.23583333333335 -11.0752000000000 4.45387254901962 10.1356862745098 7.30544117647060;
18.8560294117647 40.8409313725491 65.6118627450982 25.5301470588235 36.8114705882353 1.70803921568647 52.8283823529414 23.4644117647061 37.1732352941178 -11.7409333333331 4.62122549019627 10.2035294117649 7.77921568627470;
55.4593137254902 9.53024509803928 48.0181372549020 31.4579411764706 37.1721078431373 9.73049019607849 62.2650490196078 33.1270098039216 6.15740196078438 -0.880666666666585 12.5710784313726 18.3476960784314 15.4196568627452]
I want to calculate the cumalative sum of each row of the matrix and the matrix array, separately
Which is the most efficient way without creating a for loop?
May someone help me with an efficient code?
0 个评论
采纳的回答
Fabio Freschi
2019-10-8
For the matrix
Msum = cumsum(M,2)
For the cell array
Gsum = cellfun(@cumsum,G,'UniformOutput',false)
7 个评论
更多回答(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!