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 件のコメント

Benjamin Anderson-Sackaney
Benjamin Anderson-Sackaney 2016 年 5 月 19 日
I see what you're saying and looking at this with a fresh mind, the problem makes sense to me now. Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by