Create matrix with double rows of [-1 1]
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
Hey guys, I want to create a matrix which looks the following:
-1  0  0  0
 1  0  0  0
 0 -1  0  0
 0  1  0  0
 0  0 -1  0
 0  0  1  0
 0  0  0 -1
 0  0  0  1
and so on. Does anyone know a good way to do that? Maybe there is a helpful command for that :)
Thanks a lot :)
Oh, sorry, an edit:
I would also have an even more complex matrix, which would look the following...
   0  0  0  0
  -1  0  0  0
   0  1  0  0
   0 -2  0  0
   0  0  2  0
   0  0 -3  0
   0  0  0  3
   0  0  0 -4
Any suggestions? :)
0 Commenti
Risposta accettata
Più risposte (2)
  Andrei Bobrov
      
      
 il 10 Lug 2014
        1.
out1 = kron(eye(4),[-1;1]);
2.
out2 = kron(eye(4),[1;1]);
out2(out2>0) = bsxfun(@plus,[1;-1]*(1:4),[-1;0]);
Vedere anche
Categorie
				Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!