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

1 次查看(过去 30 天)
clear all
close all
%clc

采纳的回答

Superficial
Superficial 2020-11-17
编辑:Superficial 2020-11-17
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 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by