From: Tava Eurdanceza on
Hi everyone.
I have a problem. I want to make matrix 100 x 100 with elements
1 1 0 0 0 0 ... 0 0
0 0 1 1 0 0 ... 0 0
0 0 0 0 1 1 ... 0 0
⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ... ⋮ ⋮
0 0 0 0 0 0 ... 1 1
but it is not done by inserting elements one by one.
how to create programs for the matrix?
Thanks before
From: Matt Fig on
See the help for the DIAG function.
From: Filip Leszko on
how about:
m=100;
A = eye(m);
A = A + [zeros(m,1) A(:,1:m-1)]
From: Roger Stafford on
"Tava Eurdanceza" <tava_cute(a)yahoo.com> wrote in message <hpm187$b2n$1(a)fred.mathworks.com>...
> Hi everyone.
> I have a problem. I want to make matrix 100 x 100 with elements
> 1 1 0 0 0 0 ... 0 0
> 0 0 1 1 0 0 ... 0 0
> 0 0 0 0 1 1 ... 0 0
> &#8942; &#8942; &#8942; &#8942; &#8942; &#8942; ... &#8942; &#8942;
> 0 0 0 0 0 0 ... 1 1
> but it is not done by inserting elements one by one.
> how to create programs for the matrix?
> Thanks before

As you have written it, that matrix cannot be a square 100 x 100. It would have to have twice as many columns as rows. What did you really intend?

Roger Stafford
From: Roger Stafford on
"Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <hpm921$1rn$1(a)fred.mathworks.com>...
> As you have written it, that matrix cannot be a square 100 x 100. It would have to have twice as many columns as rows. What did you really intend?
> ........
--------------
In case you decide that a 100 x 200 size matrix is what you really want, you can do this:

n = 100;
A = zeros(n,2*n);
A([1:2*n+1:n*(2*n-1),n+1:2*n+1:2*n^2]) = 1;

Roger Stafford