Index exceeds the number of array elements (2).

New to mat lab something wrong with line 9. I just corrected the D(n) still don't know whats going wrong.
clear all
temp = [850:0.1:950];
time = [0:004:4];
for n= 1:1000
D(n)=(2.3.*10^(-5)).*exp((-148000)./(8.314.*((temp(n))+273.15)));
end
for x = 1:1:1000
for k = 1:1:1000
InsideErf(k) = 0.002./((D(x)./(time(k)) ;
end
end

Answers (1)

D=(2.3.*10^(-5)).*exp((-148000)./(8.314.*((temp)+273.15)));
That overwrites all of D in every iteration of the n loop. You should be assigning to D(n) instead of to D alone.

2 Comments

thank you totally right. Do you know anything that might be going wrong in line 9?
clear all
temp = [850:0.1:950];
time = [0:004:4];
for n= 1:1000
D(n)=(2.3.*10^(-5)).*exp((-148000)./(8.314.*((temp(n))+273.15)));
end
for x = 1:1:1000
for k = 1:1:1000
InsideErf(k) = 0.002./((D(x)./(time(k)) ;
% 1 0 12 3 2 3 4 32
end
end
The digits indicate the number of open bracket levels "after" executing the character directly above. So at the end of the line, there are still two ( that do not have a matching )

Sign in to comment.

Asked:

on 5 Dec 2021

Commented:

on 5 Dec 2021

Community Treasure Hunt

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

Start Hunting!