From: Baris on
Hi all,

How do you construct this following in Matlab?? and for the
similar probs in what way should i think?

0 0 0 0 1
0 0 0 1 2
0 0 1 2 3
0 1 2 3 4
1 2 3 4 5

thanks in advance!

Baris
From: us on
Baris:
<SNIP mat-gymnastics 101...

one of the very many solutions

n=5;
m=rot90(tril(toeplitz(1:n,1:n)),1)

us
From: Jos on
Baris wrote:
>
>
> Hi all,
>
> How do you construct this following in Matlab?? and for the
> similar probs in what way should i think?
>
> 0 0 0 0 1
> 0 0 0 1 2
> 0 0 1 2 3
> 0 1 2 3 4
> 1 2 3 4 5
>
> thanks in advance!
>
> Baris

The following functions are handy in this case:
TOEPLITZ, HANKEL, TRIL, TRIU, FLIPDIM, ROT90

For instance,

n = 5 ;
rot90(hankel(n:-1:1),2)

For a similar problem see
<http://newsreader.mathworks.com/WebX/.ef4b523?50@@>

By the way, the following seems to be a "bug" (at least in R13)

flipdim(hankel(n:-1:1),[1 2])
Warning: Input arguments must be scalar.
Warning: Colon operands must be real scalars.

although it produces the desired result.

Jos
From: cal on
> How do you construct this following in Matlab?? and for the
> similar probs in what way should i think?
> 0 0 0 0 1
> 0 0 0 1 2
> 0 0 1 2 3
> 0 1 2 3 4
> 1 2 3 4 5

really easy:
>> cumsum(cumsum(fliplr(eye(5))))