# matrix inside a matrix

1 visualizzazione (ultimi 30 giorni)
SAZZAD HOSSAIN il 5 Apr 2012
Hello everyone,
I am working on building an energy momentum relationship (E-K diagram) for a semiconductor. I am treating my periodic system with 100 unit cells and so i have a 100-by-100 matrix. The matrix is such that all the diagonal elements look like the same (say 3 3 3 ...... all across the diagonal), all the upper diagonal elements look the same (2 2 .......)and all the lower diagonal elements look the same too. The problem is i havent been able to build my 100 by 100 matrix when the diagonal elements look like say 3 4 5 3 4 5 3 4 5 ............ The same thing goes for the variation in upper and lower diagonal elements. Can anyone please help me what sort of command should i use?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Seth DeLand il 5 Apr 2012
The REPMAT and DIAG commands should be able to do what you need:
A = repmat([3;4;5],5,1)
B = diag(A,0)
Check out the example in the documentation for DIAG on how to expand this to tridiagonal matrices.
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
SAZZAD HOSSAIN il 6 Apr 2012
Thanks Seth. It works like a charm.

Accedi per commentare.

### Categorie

Scopri di più su Operating on Diagonal 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!

Translated by