Index exceeds the number of array elements (3).

2 views (last 30 days)
Amna Awad
Amna Awad on 23 Nov 2020
Answered: Sindhu Karri on 26 Nov 2020
I'm getting an error with the linspace i have created. im trying to calculate 'TLab'
the error im getting is 'Index exceeds the number of array elements (3).
Error in labmaterials (line 76)
Ms(iii)=2/pi*(w1*log(tan(acos(w1/l_vector(iii)))+l_vector(iii)/w1)+l_vector(iii)*(pi/2)-l_vector(iii)*acos(w1/l_vector(iii)));
this is my code
dpag=linspace(0,3,1000);
for iii =[1:1000]
d=dpag(iii);
Ms(iii)=2/pi*(w1*log(tan(acos(w1/l_vector(iii)))+l_vector(iii)/w1)+l_vector(iii)*(pi/2)-l_vector(iii)*acos(w1/l_vector(iii)));
TLab(iii)=a2*u*b/Ms(iii);
Yield2(iii)=M*Ty1(iii);
end

Answers (1)

Sindhu Karri
Sindhu Karri on 26 Nov 2020
Hii,
According to my understanding the error 'Index exceeds the number of array elements (3)' is because of using an array (probably l_vector)of size 3 inside for loop which runs 1000 times trying to access out of bound array elements.

Community Treasure Hunt

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

Start Hunting!