error: Array indices must be positive integers or logic

Respuestas (2)

VBBV
VBBV el 2 de Feb. de 2024
y(i) = y(i) + 1;
instead of
y(II) = y(II) + 1;

2 comentarios

VBBV
VBBV el 2 de Feb. de 2024
Editada: VBBV el 2 de Feb. de 2024
The value of II may be a floatpoint number. MATLAB uses integer and 1 based indexing for accessing array elements
thank you for the response. i have changed it and it is still giving me the same error message.

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 2 de Feb. de 2024
Due to floating point round-off, the result A+(B*x(i)) might not be exactly an integer. You should round() it.

2 comentarios

when i try round() i recieve a different message
You have not posted enough context to really give you an answer.
But I suspect that you should have made x one element shorter. Something along the line of
x = linspace(xmin, xmax, number_of_steps+1);
x = x(1:end-1);

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 2 de Feb. de 2024

Comentada:

el 2 de Feb. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by