Error "Index in position 2 exceeds array bounds (must not exceed 1)."

1 回表示 (過去 30 日間)
Andrea Mira
Andrea Mira 2021 年 1 月 19 日
編集済み: KALYAN ACHARJYA 2021 年 1 月 19 日
Hi,
Could you help me in this problem??
"Index in position 2 exceeds array bounds (must not exceed 1)."
Error in
xa(k,t)= xa(k,t-1)+(vxai(k,t)/3600)*At;
My code is:
number_of_runs=100;
xa=ones(number_of_runs,1000);
ya=ones(number_of_runs,1000);
xa(1)=90; ya(1)=70;
xb(1)=50; yb(1)=20;
At=1;
va=500;
vxai=ones(number_of_runs,1000);
vyai=ones(number_of_runs,1000);
d=ones(number_of_runs,999);
for k=1:number_of_runs
i1=normrnd(0,25);
vxai(k,1)=(va+i1)
vyai(k,1)=(va+i1)
for t=2:1000
xa(k,t)= xa(k,t-1)+(vxai(k,t)/3600)*At;
ya(k,t)= ya(k,t-1)+(vyai(k,t)/3600)*At;
end
d(k,t-1)=xa(k,t-1)-ya(k,t-1)
end
Thanks in advance!!

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 1 月 19 日
編集済み: KALYAN ACHARJYA 2021 年 1 月 19 日
Problem due to typo error (Note MATLAB is case sensitive). The preallocated variable named as Vxai, Vyai (upper case V), later used vxai, vyai (lower case) within the loop. More "At", not defined.
Please modify the code as suggested, there will be no coding error.
  2 件のコメント
Andrea Mira
Andrea Mira 2021 年 1 月 19 日
編集済み: Andrea Mira 2021 年 1 月 19 日
Thank you for the answer
I made the mistakes when copying the script code to this website
In the MATLAB script I have corrected these mistakes but it still not working.
MATLAB shows the same error
Error "Index in position 2 exceeds array bounds (must not exceed 1)."
If you could give me any orientation I will be grateful
KALYAN ACHARJYA
KALYAN ACHARJYA 2021 年 1 月 19 日
編集済み: KALYAN ACHARJYA 2021 年 1 月 19 日
What you are trying to do, I have no idea, just I have rectifed the error only. Please define the "At" with typical value.
number_of_runs=100;
xa=ones(number_of_runs,1000);
ya=ones(number_of_runs,1000);
xa(1)=90; ya(1)=70;
xb(1)=50; yb(1)=20;
va=500;
Vxai=ones(number_of_runs,1000);
Vyai=ones(number_of_runs,1000);
At=????; % Define it
d=zeros(100,999);
for k=1:number_of_runs
i1=normrnd(0,25);
Vxai(k,1)=(va+i1);
Vyai(k,1)=(va+i1);
for t=2:1000
xa(k,t)= xa(k,t-1)+(Vxai(k,t)/3600)*At;
ya(k,t)= ya(k,t-1)+(Vyai(k,t)/3600)*At;
end
d(k,t-1)=sqrt((xa(k,t-1)-ya(k,t-1)).^2);
end

サインインしてコメントする。

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by