How to solve this index exceeds matrix dimensions error?
Mostrar comentarios más antiguos
Hello this is my code:
N = 30;
Sw = 0;
ni=8; %numero campioni
for i = 1:N
for j = 1:ni
x_diff = X(i,j) - mean(X(i,2));
Sw = Sw + (x_diff * x_diff');
end
end
Sb = 0;
for i = 1:N
x_diff = mean(X(i,N)) - mean(X);
Sb = Sb + (N(i) * x_diff * x_diff');
end
how can i solve the problem of the index exceeds matrix dimensions?
5 comentarios
Birdman
el 21 de Nov. de 2017
What is X?
Jessica Frau
el 21 de Nov. de 2017
If X has one column as you say, then why you try to reach to 8th column in first nested for loop and 2nd column in mean operation?
for i = 1:N
for j = 1:ni
x_diff = X(i,j) - mean(X(i,2));
Sw = Sw + (x_diff * x_diff');
end
end
Jessica Frau
el 21 de Nov. de 2017
Editada: Jessica Frau
el 21 de Nov. de 2017
Guillaume
el 21 de Nov. de 2017
I don't understand your equations, particularly why there is a transpose symbol on something that look like scalar values, but in any case, it is clear that X is supposed to be at least a 2D matrix.
If you don't have a 2D matrix I'm not sure how we can help.
Respuestas (1)
Guillaume
el 21 de Nov. de 2017
As you've stated X is a Nx1 vector. Yet, you have:
X(i, j)
X(i, 2)
X(i, N)
in your code. How are you expecting that to work?
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
