Say I'm given a symmetric row vector with an odd length where each element is smaller than the next one in the first half of the vector and each element is bigger than the next one in the second half and the middle element is the biggest. (e.g [1 2 3 2 1]
or [10 20 50 20 10]
).
I want to create a square matrix where this row vector is its middle row and the equivalent column vector (v'
) is its middle column and each other row or column is a reduced version of the given vector according to the middle element in this row or column. And when there are no more "original elements" we put 0
.
Examples:
if v = [1 2 3 2 1]
we get
0 0 1 0 0
0 1 2 1 0
1 2 3 2 1
0 1 2 1 0
0 0 1 0 0
if v = [3 5 3]
we get
0 3 0
3 5 3
0 3 0
What I did so far: I managed to create a matrix with v
as the middle row and v'
as the middle column with this code I wrote:
s = length(vector);
matrix= zeros(s);
matrix(round(s/2),:) = vector;
matrix(:, round(s/2)) = vector';
but got stuck with assigning the other values.