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 comentarios

Birdman
Birdman el 21 de Nov. de 2017
What is X?
X is a vector X = (N, 1)
Birdman
Birdman el 21 de Nov. de 2017
Editada: Birdman 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
Jessica Frau el 21 de Nov. de 2017
Editada: Jessica Frau el 21 de Nov. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Guillaume
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

Preguntada:

el 21 de Nov. de 2017

Comentada:

el 21 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by