How to solve this index exceeds matrix dimensions error?
Afficher commentaires plus anciens
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 commentaires
Birdman
le 21 Nov 2017
What is X?
Jessica Frau
le 21 Nov 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
le 21 Nov 2017
Modifié(e) : Jessica Frau
le 21 Nov 2017
Guillaume
le 21 Nov 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.
Réponses (1)
Guillaume
le 21 Nov 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?
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
