Array indices must be positive integers or logical values.
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Mohammed Shabbir Ahmed
el 8 de Mayo de 2023
Editada: Mohammed Shabbir Ahmed
el 9 de Mayo de 2023
gcoord
0 0
0 0
0 0
0 0
.........
Array indices must be positive integers or logical values.
this error is coming please help
0 comentarios
Respuestas (1)
Steven Lord
el 8 de Mayo de 2023
Usually this happens when you try to use 0 as an index. Indices in MATLAB start at 1 not 0.
x = 1:10;
This will work:
y(1:2:20) = x.^2
This won't. I've wrapped it in try and catch so code later in this answer can run.
try
z(0:2:19) = x.^2
catch ME
fprintf("This code threw error: %s\n", ME.message)
end
To fix this error, use indices that start at 1 not 0.
Alternately you could be trying to call a function but there's a variable by that name instead. In this case rename the variable so it doesn't have the same name as the function.
q = sin(pi)
sin = 42;
w = sin(pi)
If you need further help you will need to show us a small sample of code with which you can reproduce this error.
0 comentarios
Ver también
Categorías
Más información sobre Logical 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!