Error - Index exceeds the number of array elements (1)

1 visualización (últimos 30 días)
Telema Harry
Telema Harry el 17 de Nov. de 2020
Editada: Telema Harry el 17 de Nov. de 2020
clear all
close all
%clc

Respuesta aceptada

Superficial
Superficial el 17 de Nov. de 2020
Editada: Superficial el 17 de Nov. de 2020
On a simple level, that error occurs because you are trying to 'index' a variable that isn't big enough for the index position it's seeking. It's like me asking you to please find the 4th number in the vector [1 2 3]. You can't do it; it doesn't exist.
But in general, your code is just quite confused. Where did you find it? There are a few problems, it's hard to know where to start.
Your 'x' series is initially defined as zeroes(1,length(t)). In your example, 1x1001. This means that when you try to index x(a,i) it will fail when a > 1. But anyway, you have already changed it so x = [0.03;0.01]; Now x is only 1x2 so you won't be able to index x(a,i) when a > 1 or i > 2.
In your ODE function, you have an input argument 't' but this is unused.
I think you may need to start with something more basic to get a better understanding of how to write in Matlab code E.g. defining variables and indexing.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by