Question about summations from excel (backwards sum)
3 次查看(过去 30 天)
显示 更早的评论
Hello, I have an imported excel file. Say I have 2, 1x20 Matrix (set as A and B respectively). How can I make an upside down sum between my matrices? Instead of going from i=0 to i=20 , I want to go from i=20 to i=0. An easy fix could be re-arranging the excel files but I wanna know if theres a way around with matlab.
0 个评论
回答(3 个)
Roger Stafford
2014-2-3
编辑:Roger Stafford
2014-2-3
s = sum(fliplr(A)+fliplr(B));
Note: Whatever order 'sum' would have taken with A+B will be reversed.
0 个评论
Wayne King
2014-2-3
编辑:Wayne King
2014-2-3
There are a couple issues here. A sum that goes from 0 to 20 has 21 elements not 20 as you indicate. Further, summation is commutative so why does it matter what order you sum in?
A = randn(2,20);
sum(A,2)
B = fliplr(A); % reverse the elements in the rows of A
sum(B,2)
What have I misunderstood?
fliplr() reverse the rows of A (reverses each row of A)
Azzi Abdelmalek
2014-2-3
Your question is not clear, maybe you want
A=[ 1 2 3 4]
B=[10 20 30 40]
out=cumsum(fliplr(A+B))
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!