Array problem on finding slopes

1 view (last 30 days)
Mohamad Uzir
Mohamad Uzir on 13 Jun 2021
Edited: Walter Roberson on 13 Jun 2021
I have a problem with error;
"Index exceeds the number of array elements (10)."
The code goes like this:
A=[0,198.6026,397.2053,993.01346,2376.65783,3968.16977,4566.799,5161.454,6956.4044,9930.1346];
B=[0.29835,0.3978,0.467415,0.546975,0.745875,0.975375,1.09395,1.3923,2.56275,4.5288];
LS=zeros(1,5);
RS=zeros(1,5);
for n=1:5
for i=1:length(A)
LS(n)=B(i+1)-B(i)/(A(i+1)-A(i));
RS(n)=B(i+2)-B(i+1)/(A(i+2)-A(i+1));
LS(n+1)=B(i+3)-B(i+2)/(A(i+3)-A(i+2));
RS(n+1)=B(i+4)-B(i+3)/(A(i+4)-A(i+3));
LS(n+2)=B(i+5)-B(i+4)/(A(i+5)-A(i+4));
RS(n+2)=B(i+6)-B(i+5)/(A(i+6)-A(i+5));
LS(n+3)=B(i+7)-B(i+6)/(A(i+7)-A(i+6));
RS(n+3)=B(i+8)-B(i+7)/(A(i+8)-A(i+7));
LS(n+4)=B(i+9)-B(i+8)/(A(i+9)-A(i+8));
RS(n+4)=B(i+length(A))-B(i+9)/(A(i+length(A))-A(i+9));
end
end
  2 Comments
Mohamad Uzir
Mohamad Uzir on 13 Jun 2021
Hi Scott. Thank you for pointing that out. And the for loop for n is also not required. I just realized that about an hour I posted the question. The problem is now solved. Cheers.

Sign in to comment.

Answers (0)

Tags

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!