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

zaid albeik
zaid albeik 2021년 11월 23일
i tryed to put for k=3:Ns -1
but another error apears
Error using plot
Vectors must be the same length.
Error in First_Second_Derivative (line 21)
plot(t,Ipeak,'*k',t,Im_correct,'r','LineWidth',1)

댓글을 달려면 로그인하십시오.

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 12월 29일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2021년 11월 23일

답변:

2021년 12월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by