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.

 Respuesta aceptada

Geoff Hayes
Geoff Hayes el 19 de Mayo de 2016
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 comentario

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Environment and Settings en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by