Index exceeds matrix dimensions?? Error in my script..help please?

Hi everyone, I need some help. In the script (that I'll link) I get this error:
Index exceeds matrix dimensions.
Error in Integration (line 28)
fi1(i+1)= fi1(i) + dt*(w-s.*N1(j)*cos(fi1(i)));
and I don't know how and why, can you help me please? Is very important..

 Réponse acceptée

clear
close all
dt=0.1;
t=(1:dt:10);
t=t(:);
N1=(0:1:99);
N2=(0:1:99);
N3=(0:1:99);
N4=(0:1:99);
n1=fliplr(N1);
n2=fliplr(N2);
n3=fliplr(N3);
n4=fliplr(N4);
w=0.04;
s=0.0052;
fi1=zeros(length(t),1);
fi2=zeros(length(t),1);
fi3=zeros(length(t),1);
fi4=zeros(length(t),1);
for i=1:length(t)-1
for j=1:length(N1)
if 0<fi4(i)<=pi/2
fi1(i+1)= fi1(i) + dt*(w-s.*N1(j)*cos(fi1(i)));
elseif pi/2<fi4(i)<=pi
fi1(i+1)= fi1(i) + dt*(w-s.*n1(j)*cos(fi1(i)));
end
end
for j=1:length(N2)
if 0<fi1(i)<=pi/2
fi2(i+1)= fi2(i) + dt*(w-s.*N2(j)*cos(fi2(i)));
elseif pi/2<fi1(i)<=pi
fi2(i+1)= fi2(i) + dt*(w-s.*n2(j)*cos(fi2(i)));
end
end
for j=1:length(N4)
if 0<fi3(i)<=pi/2
fi4(i+1)= fi1(i) + dt*(w-s.*N4(j)*cos(fi4(i)));
elseif pi/2<fi3(i)<=pi
fi4(i+1)= fi4(i) + dt*(w-s.*n4(j)*cos(fi4(i)));
end
end
for j=1:length(N3)
if 0<fi2(i)<=pi/2
fi3(i+1)= fi3(i) + dt*(w-s.*N3(j)*cos(fi3(i)));
elseif pi/2<fi2(i)<=pi
fi3(i+1)= fi3(i) + dt*(w-s.*n3(j)*cos(fi3(i)));
end
end
end
subplot( 2, 2, 1)
plot(t,sin(fi1(:,1)),'-o')
xlabel('time')
ylabel('sin(phi1) LF')
subplot( 2, 2, 2)
plot(t,sin(fi2(:,1)),'-.');
xlabel('time')
ylabel('sin(phi2) RF')
subplot( 2, 2, 3)
plot(t,sin(fi3(:,1)),'r-');
xlabel('time')
ylabel('sin(phi3) LH')
subplot( 2, 2, 4)
plot(t,sin(fi4(:,1)),'k--');
xlabel('time')
ylabel('sin(phi4) RH')

3 commentaires

Thank you soooo much! It works!
for i=1:length(D)
if (h_(i,T)~=D(i))
eps(T)=eps(T)+D(i,:);
end
end
please help for this code
indes exceeds matrix dimension

Connectez-vous pour commenter.

Plus de réponses (1)

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by