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

1 Ansicht (letzte 30 Tage)
Andrea Mira
Andrea Mira am 19 Jan. 2021
Bearbeitet: KALYAN ACHARJYA am 19 Jan. 2021
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!!

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 19 Jan. 2021
Bearbeitet: KALYAN ACHARJYA am 19 Jan. 2021
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 Kommentare
Andrea Mira
Andrea Mira am 19 Jan. 2021
Bearbeitet: Andrea Mira am 19 Jan. 2021
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 am 19 Jan. 2021
Bearbeitet: KALYAN ACHARJYA am 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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by