Error "Index in position 2 exceeds array bounds (must not exceed 1)."
Afficher commentaires plus anciens
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!!
Réponses (1)
KALYAN ACHARJYA
le 19 Jan 2021
Modifié(e) : KALYAN ACHARJYA
le 19 Jan 2021
0 votes
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 commentaires
Andrea Mira
le 19 Jan 2021
Modifié(e) : Andrea Mira
le 19 Jan 2021
KALYAN ACHARJYA
le 19 Jan 2021
Modifié(e) : KALYAN ACHARJYA
le 19 Jan 2021
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
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!