Problem 56060. Sub-Diagonal Sum
Given a (m x n) matrix and a value r {1,-1}, change every element to the sum of the diagonal led by the element.
r=1 > regular diagonal (top left to bottom right)
r=-1 > flipped/cross diagonal (top right to bottom left)
in=[1 2 3 4
5 6 7 8
1 3 2 0]
r=1
out=[9 9 11 4
8 8 7 8
1 3 2 0]
%explaination
(1,1) diagonal - [1 6 2], sum = 9
(1,3) diagonal - [3 8], sum = 11
(2,1) diagonal - [5 3], sum = 8
(2,4) diagonal - [8], sum = 8
in=[1 -2 3 -4
5 -6 7 -8
1 3 -2 0]
r=-1
out=[1 3 -2 6
5 -5 10 -10
1 3 -2 0]
%explaination
(1,1) diagonal - [1], sum = 1
(1,3) diagonal - [3 -6 1], sum = -2
(2,2) diagonal - [-6 1], sum = -5
(2,4) diagonal - [-8 -2], sum = -10
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers11
Suggested Problems
-
6076 Solvers
-
280 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1296 Solvers
-
Construct an index vector from two input vectors in vectorized fashion
442 Solvers
-
Where is the number that you want to find?
89 Solvers
More from this Author43
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!