Error "Index in position 2 exceeds array bounds (must not exceed 1)."
1 回表示 (過去 30 日間)
古いコメントを表示
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!!
0 件のコメント
回答 (1 件)
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 件のコメント
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 Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!