Error: Attempted to access z(3); index out of bounds because numel(z)=2.

1 回表示 (過去 30 日間)
Stephany
Stephany 2013 年 3 月 15 日
File:
function [yprime] = orbit(t,z)
a = z(2);
b =-((1.24*10^12)*z(1))/((z(1)^2+z(3)^2)^(3/2));
c = z(4);
d =-((1.24*10^12)*z(3))/((z(1)^2+z(3)^2)^(3/2));
end
What does this error mean, and how do I go about fixing it?

回答 (1 件)

Vishal Rane
Vishal Rane 2013 年 3 月 15 日
From the error, it seems that 'z' is an array of length 2. Since you are trying to access the third element using 'z(3)', MATLAB is giving you an index out of bounds error.
Check the value of the variable 'z' that is passed to the function 'orbit'

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by