# More sophisticated code than a for loop with i is large

1 visualizzazione (ultimi 30 giorni)
Bran il 10 Lug 2013
Hi there I am trying to calculate a scatter matrix for some data. so basically my Eigen values are in a matrix of the form; [e11 e12 e13; e21 e22 e23; e31 e32 e33; ...... e101 e102e103]
and my scatter matrix is of the form;
[e11^2 + e21^2 + e31^2 + ... e101^2, e11e12 + e21e22 + ... +e101e102, e11e13 + ... e101e103; e11e12 + e21e22 + ... +e101e102, e12+e22+e32+..e102, e12e13+e22e23+...+e102e103; e11e13 + ... e101e103, e12e13+e22e23+...+e102e103; e13^2+e23^2+...+e103^2]
Now in some cases instead of n = 10 as is the case above n =in the thousadns. is there a neat way to code for this?
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Jan il 10 Lug 2013
How is "n=10" related to the posted code. I think, names like e101e103 are such ugly, that it is near to impossible to read the code.

Accedi per commentare.

### Risposta accettata

Andrei Bobrov il 10 Lug 2013
Modificato: Andrei Bobrov il 10 Lug 2013
Let e = [e11 e12 e13; e21 e22 e23; e31 e32 e33; ...... e101 e102e103];
out = e.'*e;
out(2,2) = sum(e(:,2));
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Più risposte (1)

Hugo il 10 Lug 2013
Please notice that in the "scatter matrix" that you showed as an example there are elements that are repeated, and the structure is not exactly a matrix.
So, it seems that the matrix of eigenvalues, let's say A, is of size n x 3. Is the scatter matrix of this data what you want? You can simply do
A'*A, and it will return a 3x3 matrix where each element Aij has the values:
Aij= sum_n ( eni * enj ), which partially coincides with your example.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Particle & Nuclear Physics 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