Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
anand kumar
anand kumar am 26 Mai 2020
Beantwortet: Ayush Goyal am 19 Jun. 2020
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 Kommentar
Stephen23
Stephen23 am 26 Mai 2020
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Ayush Goyal
Ayush Goyal am 19 Jun. 2020
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

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by