I keep getting index exceeds matrix dimensions but I don't understand why. I'm trying to sum the elements in an array.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Maryam Ansari
el 1 de Feb. de 2016
Comentada: Star Strider
el 1 de Feb. de 2016
Below is a simple code. I'm creating an array m which contains all odd numbers between 1 and 52015. I'm trying to sum all the elements in the array. I keep getting "Index exceeds matrix dimensions.Error in oddsum (line 33), odd = sum(n). I wasn't sure if transposing m would help solve the problem, but I don't understand how the index exceeds the dimensions of my matrix.
m = 1:2:52015;
n = m';
odd = sum(n); -- this is where my error is
Respuesta aceptada
Star Strider
el 1 de Feb. de 2016
Somewhere earlier in your code you have a variable named ‘sum’ that is ‘overshadowing’ the sum function. Rename the variable to something other than ‘sum’ (or the name of any other MATLAB function) and the problem will disappear.
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!