Special Matlab Matrix

Is there a MATLAB function to create this matrix ?:

[1 2 3 4 5 6 7 ... n;
 2 3 4 5 6 7 8 ... n+1;
 3 4 5 6 7 8 9 ... n+2;
 ...;
 n n+1 n+2     ... 2*n-1];

Is there a name for him?

Thanks.

+4
source share
2 answers

Yes, indeed, there is a name for this matrix. It is known as the Hankel matrix .

Use the function hankelin MATLAB:

out = hankel(1:n,n:2*n-1);

Example with n=10:

out = 

     1     2     3     4     5     6     7     8     9    10
     2     3     4     5     6     7     8     9    10    11
     3     4     5     6     7     8     9    10    11    12
     4     5     6     7     8     9    10    11    12    13
     5     6     7     8     9    10    11    12    13    14
     6     7     8     9    10    11    12    13    14    15
     7     8     9    10    11    12    13    14    15    16
     8     9    10    11    12    13    14    15    16    17
     9    10    11    12    13    14    15    16    17    18
    10    11    12    13    14    15    16    17    18    19

In addition, you may want to use bsxfun. This is certainly possible:

out = bsxfun(@plus, (1:n), (0:n-1).');

, , , repmat, , , . repmat bsxfun, .

+5

repmat(1:n,n,1)+repmat((1:n)',1,n)-1
+2

Source: https://habr.com/ru/post/1614014/


All Articles