Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Seeking help creating a double matrix of ones and minus ones

Asked by John

John (view profile)

on 21 Aug 2013
Accepted Answer by Iain

Iain (view profile)

Hello,

I'm relatively new to matlab and I'm trying to create a matrix like the example below. But I can't seem to get the code correct. I've tried the following code neither of which are correct. Would somebody be able to help me out?

Much appreciated

N=5;
ot = ones(N,1);
A = spdiags([-ot -ot],[0 N],N,N*2); 

and

A = sparse(tril(ones(N)));
1    -1
11   -1-1
111  -1-1-1
1111 -1-1-1-1
11111-1-1-1-1-1

0 Comments

John

John (view profile)

Tags

Products

No products are associated with this question.

1 Answer

Answer by Iain

Iain (view profile)

on 21 Aug 2013
Accepted answer
 startpoint = eye(desired_size);
 positives = cumsum(startpoint)
 whole_thing = [positives -positives]

0 Comments

Iain

Iain (view profile)

Contact us