Search code examples
matlabtoeplitz

How do I enter a flipped toeplitz matrix in matlab?


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.


Solution

  • 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.