How do I enter a flipped toeplitz matrix in matlab?

48 Views Asked by At

What is a clean way to use vector a to make matrix A in matlab? Notice that the bottom right corner is padded with ones. Sometimes I will want to pad it with something else, like zeros.

% use this vector
a = [4, 2, 5, 6]

% to make this matrix
A = [
    4, 2, 5, 6;
    2, 5, 6,     1;
    5, 6,     1, 1]

I tried using combinations of flip and toeplitz. I succeeded, but it got messy.

2

There are 2 best solutions below

2
Ryan Hubscher On BEST ANSWER

I used the hankel() function.

This works, but produces a warning:

A = hankel(a, ones(1,3))'

This is longer, but has no warnings:

A = hankel(a, [a(end) ones(1,2)])'

Andras Deak gave us the right answer in his comment.

2
John Bofarull Guix On
a=randi([-10 10],1,4)  % input 1D vector
A1=toeplitz(a);
A2=flip(A2,1);
A3=triu(toeplitz(A2)) + tril(ones(size(A2)),-1);
A3=flip(A3,1);
A3(end,:)=[]   % result