Data is a 120x2 double
Code is as follows, also screenshotted in picture
SizeData=size(Data);
MeanX1=sum(Data(:,1))\SizeData(1);
MeanY1=sum(Data(:,2))\SizeData(1);
MeanX2=mean(Data(:,1));
MeanY2=mean(Data(:,2));
Why would MeanY1 not equal MeanY2, and why would MeanX1 not equal MeanX2? The problem does not seem to occur when I manually make a matrix such as Data=[1,2;2,3;3,4];

답변 (1개)

Guillaume
Guillaume 2016년 2월 8일
편집: Guillaume 2016년 2월 8일

1 개 추천

Don't you think that the \ in your code look odd?
You're doing a left division. That is, you're doing
MeanX1 = n / sum(x)
which of course is not the definition of the mean. Correct code:
MeanX1 = sum(Data(:,1)) / SizeData(1); %Note the direction of '/'

댓글 수: 1

Alex
Alex 2016년 2월 8일
Thank you. I'm working with a smaller keyboard than I usually do, so I guess that's how I didn't notice which slash I was pressing

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

카테고리

태그

질문:

2016년 2월 8일

댓글:

2016년 2월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by