What is the meaning of this line?

조회 수: 1 (최근 30일)
vimal kumar chawda
vimal kumar chawda 2019년 12월 3일
댓글: Walter Roberson 2019년 12월 5일
Hello
I want to know why we are using the line
sumX2=sumX2+(listOfPoints(1,i)-Xc(1,:))^2;
Why 2 times sumX2, and what is the purpose of using 2 times, and can anyone let me know?
What are the changes in the result ?
sumX2=0; sumY2 =0; sumZ2=0; sumXY=0; sumYZ=0; sumXZ=0;
for i=1:N
sumX2 = sumX2 + (listOfPoints(1,i)-Xc(1,:))^2;
sumY2 = sumY2 + (listOfPoints(2,i)-Xc(2,:))^2;
sumZ2 = sumZ2 + (listOfPoints(3,i)-Xc(3,:))^2;
sumXY = sumXY + (listOfPoints(1,i)-Xc(1,:))*(listOfPoints(2,i)-Xc(2,:));
sumYZ = sumYZ + (listOfPoints(2,i)-Xc(2,:))*(listOfPoints(3,i)-Xc(3,:));
sumXZ = sumXZ + (listOfPoints(1,i)-Xc(1,:))*(listOfPoints(3,i)-Xc(3,:));
end

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 3일
편집: KALYAN ACHARJYA 2019년 12월 3일
"why 2 times sumX2 and what is the purpose of using 2times and can anyone do let me know?"
sumX2=sumX2+...
Here sumX2 updated during entire iteration
Let say example
sumX2=1;
for i=1:4;
sumX2=sumX2+i;
end
#
In first Iteration, ehen i=1
sumX2=sumX2+i=1+1=2
In 2nd Iteration, ehen i=2, sumX2=2
sumX2=sumX2+i=2+2=4
...so on..
In each ireration sumX2 used the last updated values, for current sumX2 calculation
Hope it helps!
  댓글 수: 5
KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 12월 5일
Great!
Keep Learning Vimal
Walter Roberson
Walter Roberson 2019년 12월 5일
But i am getting only one value in this loop as respective row.
The expression (1/N)* sum(listOfPoints(1,:)) would sum the row vector listOfPoints(1,:) resulting in a scalar, and then would divide the scalar by N, resulting in a scalar. You then assign the result to Xc(1,:) which would assign the same scalar to all columns that exist in the first row of Xc. If, for example, Xc already existed with 17 columns, then all 17 columns of the first row will be assigned the exact same mean value.
The code I suggested,
Xc = mean(listOfPoints, 2);
is a little different in that it will result in Xc being exactly one column wide, no matter how big the existing Xc was. If you really need Xc to keep the same number of columns and have each column be exactly the same within each row, then there are a number of different was to achieve that, including,
Xc = mean(listOfPoints, 2) * ones(1, size(Xc,2));

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Computer Vision Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by