why do i get error "Index exceeds matrix dimensions" in this code?

p=1;
v_d(1)=0;
f_p=[];
t = 0:0.000001:1;
f=2.5;
v = 1*sin(2*pi*t*f);
d = 9*10^(-9);
j=2;
u_v=30*10^-15;
r_on=0.1*10^3;
r_off=16*10^3;
r_i=11000;
w(1)=((r_off-r_i)/(r_off-r_on))*d;
x(1)=w(1)/d;
m(1)=r_on*(w(1)/d)+r_off*(1-w(1)/d);
% f_p(1)= 1 - (2*x-1)^(2*p); %Joglekar window
% f_p(1)=j*(1 - ((x-0.5)^2+0.75)^p); %Prodromakis window
for index=2:length(t)
i(index)=v(index)/m(index-1);
v_d(index)=(u_v*r_on*i(index)*f_p(index-1))/d;
w(index)=v_d(index)*(t(index)-t(index-1))+w(index-1);
x(index)=w(index)/d;
% f_p(index)=1 - (2*x(index)-1)^(2*p); %Joglekar window
% f_p(index)=j*(1 - ((x(index)-0.5)^2+0.75)^p); %Prodromakis window
m(index)=r_on*(w(index)/d)+r_off*(1-w(index)/d);
if m(index)<r_on
m(index)=r_on;
end
if m(index)>r_off
m(index)=r_off;
end
x(index)=w(index)/d;
end
Index exceeds matrix dimensions.

댓글 수: 1

v_d(index)=(u_v*r_on*i(index)*f_p(index-1))/d;
% ^^^ this is empty, any non-empty index will throw that error.

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

답변 (1개)

Ayush Goyal
Ayush Goyal 2020년 6월 19일
From my understanding of the question you are getting index error due to f_p(index-1). Since initially you have defined f_p as empty array and you have commented both the updating part of f_p (for Joglekar/Prodromakis Window) you are getting index error. You have to enable atleast one updating part of f_p i.e. Joglekar/Prodromakis Window. Check the following code when I use Joglekar Window:
p=1;
v_d(1)=0;
f_p=[];
t = 0:0.000001:1;
f=2.5;
v = 1*sin(2*pi*t*f);
d = 9*10^(-9);
j=2;
u_v=30*10^-15;
r_on=0.1*10^3;
r_off=16*10^3;
r_i=11000;
w(1)=((r_off-r_i)/(r_off-r_on))*d;
x(1)=w(1)/d;
m(1)=r_on*(w(1)/d)+r_off*(1-w(1)/d);
f_p(1)= 1 - (2*x-1)^(2*p); %Joglekar window (Uncomment this line)
%f_p(1)=j*(1 - ((x-0.5)^2+0.75)^p); %Prodromakis window
for index=2:length(t)
i(index)=v(index)/m(index-1);
v_d(index)=(u_v*r_on*i(index)*f_p(index-1))/d;
w(index)=v_d(index)*(t(index)-t(index-1))+w(index-1);
x(index)=w(index)/d;
f_p(index)=1 - (2*x(index)-1)^(2*p); %Joglekar window (Uncomment this line)
% f_p(index)=j*(1 - ((x(index)-0.5)^2+0.75)^p); %Prodromakis window
m(index)=r_on*(w(index)/d)+r_off*(1-w(index)/d);
if m(index)<r_on
m(index)=r_on;
end
if m(index)>r_off
m(index)=r_off;
end
x(index)=w(index)/d;
end

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2020년 5월 26일

답변:

2020년 6월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by