More sophisticated code than a for loop with i is large
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Jan
2013년 7월 10일
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.
채택된 답변
Andrei Bobrov
2013년 7월 10일
편집: Andrei Bobrov
2013년 7월 10일
Let e = [e11 e12 e13; e21 e22 e23; e31 e32 e33; ...... e101 e102e103];
out = e.'*e;
out(2,2) = sum(e(:,2));
댓글 수: 0
추가 답변 (1개)
Hugo
2013년 7월 10일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!