Clear Filters
Clear Filters

Attempted to access, index out of bounds

6 views (last 30 days)
KH
KH on 5 Nov 2012
I have this problem of : ??? Attempted to access load_to_cause_primary_crack(6); index out of bounds because numel(load_to_cause_primary_crack)=5.
Error in ==> try at 29 barforce(1)=load_to_cause_primary_crack(i);
it's fine when the for loop of say, n=1:100000, but when i changed the limit to number, i'll be getting the above mentioned error. Why is this so?
Below is the code:
clear all Dbar=16; Abar=pi*Dbar^2/4; Lp=pi*Dbar; Ebar=200000; Ec=10000; fcu=30; Dp=200; Ac=Dp^2; dmax=15; tmax=2.5*sqrt(fcu); d1=1.5; Ls=0.8;
n=1; i=1; pcs=532 sc=pcs/2 number=round(sc/Ls) load_to_cause_primary_crack(i)=10000; guess(n)=0.7
for i=1:1000000
for n=1:number
bf(1)=load_to_cause_primary_crack(i);
bndf(1)=0;
if guess(n)<=d1
d_over_d1(n)=guess(n)/d1;
bndstr(n)= tmax*((d_over_d1(n))^0.4);
elseif guess(n)>d1&&guess(n)<=dmax
bndstr(n)=tmax*(dmax-guess(n))/(dmax-d1);
elseif guess(n)>dmax
bndstr(n)=0;
end
bndf_segment(n)=bndstr(n)*Ls*Lp;
bndf(n+1)=bndf(n)+bndf_segment(n);
bf(n+1)=bf(n)-bndf_segment(n);
bstr(n)=((bf(n)+bf(n+1))/2)/(Ebar*Abar);
concstr(n)=((bndf(n)+bndf(n+1))/2)/(Ec*Ac);
ss(n)=bstr(n)-concstr(n);
change(n)=ss(n)*Ls;
guess(n+1)=guess(n)-change(n);
if ss(n)<0,break,end
end
Perrslip=guess(end)/guess(1)
if Perrslip<0.005,break,end
if ss(n)<0&&guess(n)>0
load_to_cause_primary_crack(i+1)=load_to_cause_primary_crack(i)+abs(Perrslip)*load_to_cause_primary_crack(i);
elseif ss(n)>0&&guess(n)<0
load_to_cause_primary_crack(i+1)=load_to_cause_primary_crack(i)-abs(Perrslip)*load_to_cause_primary_crack(i);
end
end
Appreciate if anyone can help me in this. Thanks.
  1 Comment
Matt J
Matt J on 5 Nov 2012
You haven't shown the code that generates the error. The line
barforce(1)=load_to_cause_primary_crack(i);
appears nowhere in the code you've posted. Also, it's a bad idea to name your function "try" since that is the name of a MATLAB command/keyword.

Sign in to comment.

Answers (1)

Matt J
Matt J on 5 Nov 2012
It means you've done something like the following. Use DBSTOP to halt execution where the error occurs and inspect the sizes of the variables.
>> load_to_cause_primary_crack=1:5;
>> barforce(1) = load_to_cause_primary_crack(6)
Attempted to access load_to_cause_primary_crack(6); index out of bounds because
numel(load_to_cause_primary_crack)=5.

Community Treasure Hunt

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

Start Hunting!