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

1 visualizzazione (ultimi 30 giorni)
clear all
close all
%clc

Risposta accettata

Superficial
Superficial il 17 Nov 2020
Modificato: Superficial il 17 Nov 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.

Più risposte (0)

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by