How to solve this index exceeds matrix dimensions error?

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

What is X?
X is a vector X = (N, 1)
Birdman
Birdman le 21 Nov 2017
Modifié(e) : Birdman 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
Jessica Frau le 21 Nov 2017
Modifié(e) : Jessica Frau le 21 Nov 2017
Well, I understand the error, but now I don't know how to create the scattering matrix with my data set X. If you can help me this are the formulas of the scattering matrix.
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.

Connectez-vous pour commenter.

Réponses (1)

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

Commenté :

le 21 Nov 2017

Community Treasure Hunt

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

Start Hunting!

Translated by