I am receiving this error in my code and I cannot figure out why. Any suggestions would be greatly appreciated.
[M,N,K] = size(X);
for j=1:K,
mu(j) = mean(X(:,:,j));
X(:,:,j) = X(:,:,j) - mu(j);
end
This goal is simply to take the mean of the third component and subtract it out from itself. There's a lot more going on in the code but this point is giving me the trouble.

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 5월 19일

1 개 추천

Benjamin - put a breakpoint at the line
mu(j) = mean(X(:,:,j));
and run your code. When the debugger pauses at this line, check to see what is
mean(X(:,:,j))
Is it a scalar or a 1xN array which has the mean of each column? What are you expecting it to be?
I suspect, given your statement, that you are assuming that it is a scalar that you can then subtract out from every other element, but that isn't the case. If this is true, then what you can do is either
mu(j) = mean(mean(X(:,:,j)));
or
T = X(:,:,j);
mu(j) = mean(T(:));
See mean for details on this function.

댓글 수: 1

I see what you're saying and looking at this with a fresh mind, the problem makes sense to me now. Thanks!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by