Index exceeds array bounds.
Show older comments
for k=3:Ns
% 1st derivative
ikd=(it(k+1)-it(k-1))/(2*h);
% 2nd derivative
ikdd=(it(k+1)-2*it(k)+it(k-1))/(h^2);
% Peak current using 1st derivative and 2nd derivative
Ipeak(k)=sqrt(((ikd/wo)^2)+((ikdd/(wo^2))^2))
end
figure(4)
plot(t,Ipeak,'*k',t,Im_correct,'r','LineWidth',1)
title('first and second derivative algorithm')
legend('Calc. Im using 1st derivative and 2nd derivative','Correct Im')
xlabel('Time(s)')
ylabel(' RMS Current (A)')
grid
---------------
Index exceeds array bounds.
Error in First_Second_Derivative (line 11)
ikd=(it(k+1)-it(k-1))/(2*h);
1 Comment
zaid albeik
on 23 Nov 2021
Answers (1)
Cris LaPierre
on 29 Dec 2021
0 votes
We don't know what your variables it, Ns, wo, t, or Im_correct are, so we can't say for certain, but here are some thoughts.
It looks like Ns = length(it) since using Ns-1 in your for-loop counter fixed the exceeding array bounds errors. This is because you index it using k+1, so in the last loop when k=Ns, the index k+1 exceeds the size or it.
As for the new error, this error is because t does not have the same length as either Ipeak or Im_correct. You will need to check your variables to determine which it is. When plotting, each y value has to have a corresponding x value, and vice versa.
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!