-
Notifications
You must be signed in to change notification settings - Fork 0
/
skewshift.m
30 lines (29 loc) · 1.03 KB
/
skewshift.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function Y = skewshift( Y )
%SKEWSHIFT shifts each row of the (square) matrix Y such that the matrix
% becomes upper triangular and the overflow is added in the last column.
% Here is an example using the magic(4) matrix:
% [ 16 2 3 13; [ 16 2 3 13;
% 5 11 10 8; is turned into 0 5 11 18;
% 9 7 6 12; 0 0 9 25;
% 4 14 15 1 ] 0 0 0 34 ]
%
% Copyright 2021, C. Minz. BSD 3-Clause License.
r = size( Y, 1 );
c = size( Y, 2 );
if c < r
n = r;
else
n = c;
end
newY = zeros( r, n );
for i = 1 : r
rowovfl = min( c + i - 1, n );
rowend = rowovfl - i + 1;
if rowend > 0
newY( i, i : rowovfl ) = Y( i, 1 : rowend );
end
newY( i, rowovfl ) = newY( i, rowovfl ) + ...
sum( Y( i, max( rowend + 1, 1 ) : c ) );
end
Y = newY;
end