Sum of matrices and loop
3 次查看(过去 30 天)
显示 更早的评论
For example
x = [1 2 3 4 5 6; 7 8 9 10 11 12;13 14 15 16 17 18;1 2 3 4 5 6]
I want sum of [1 2 3 7 8 9] which is = 72 and [4 5 6 10 11 12 15 16 17 18] which is 114 , then [1 2 3 1 1 1 2 4 3] which is 18 and so on
2 个评论
采纳的回答
Image Analyst
2014-3-2
I just answered this, in http://www.mathworks.com/matlabcentral/answers/119568#comment_199374, your duplicate question. Anyway, again, you can use conv2():
result = conv2(x, ones(3), 'valid');
It gives you just what you want - the sums in a sliding window.
2 个评论
Image Analyst
2014-3-2
x = [1 2 3 4 5 6; 7 8 9 10 11 12;13 14 15 16 17 18;1 2 3 4 5 6]
theSums = conv2(x, ones(2,3), 'same') % Compute sums
theResult = theSums(1:2:end, 2:3:end) % Subsample
更多回答(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!