Error - Index exceeds the number of array elements (1)
2 views (last 30 days)
Show older comments
clear all
close all
%clc
0 Comments
Accepted Answer
Superficial
on 17 Nov 2020
Edited: Superficial
on 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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!