Why does it give me a problem stating that, Index must not exceed 1?

1 view (last 30 days)
for k=1,1:120
del_ZS1=(del_VS1)./(del_IS1)
del_ZR1=(del_VR1)./(del_IR1)
end
figure(5);
% SIDE S - trajectory of incremental positive-sequence impedance with
% marking the starting/ending point. For all of the cases. all simulation
% cases
plot(real(del_ZS1),imag(del_ZS1))
hold on
grid on
plot(real(del_ZS1(1)),imag(del_ZS1(1)),'xr')
hold on
plot(real(del_ZS1(60)),imag(del_ZS1(60)),'kr')
hold on
title('side S - Trajectory of incremental positive-sequence impedance')
legend('del_ZS1','start','end')
xlabel('Real');
ylabel('Imaginary');
  3 Comments
ADRIAN JAVIER AREITIO TRILLO
This is the complete line of code. The problem is located at: plot(real(del_ZS1(1)),imag(del_ZS1(1)),'xr')
% Pr4_S: FAULT DIRECTION DISCRIMINATION with processing signals from the side S (sending)
theta_i=1000; % CT ratio
theta_v=1; % VT ratio
n=20; % number of samples in a single fundamental frequency period
% sampling frequency: 1000 Hz
a=-0.5+i*sqrt(3)/2; % complex operator shifting by 120 deg
% Standard full-cycle FOURIER FILTRATION
%
dT=2*pi/n;
for k=1:n,
alfa=dT/2+(k-1)*dT;
FF(k)=cos(alfa)+sqrt(-1)*sin(alfa);
end;
FF=-2*FF/n;
% READING AND TRANSPOSING *.PL4 FILES
x=readpl452;
size(x);
y=x';
size(y);
% Recalculation to primary quantities
iS_a=theta_i*y(2,1:120); % side 'S' (sending) and phase 'a' current
iS_b=theta_i*y(3,1:120); % side 'S' (sending) and phase 'b' current
iS_c=theta_i*y(4,1:120); % side 'S' (sending) and phase 'a' current
vS_a=theta_v*y(8,1:120);
vS_b=theta_v*y(9,1:120);
vS_c=theta_v*y(10,1:120);
iR_a=theta_i*y(5,1:120); % side 'R' (Recieving) and phase 'a' current
iR_b=theta_i*y(6,1:120); % side 'R' (Recieving) and phase 'b' current
iR_c=theta_i*y(7,1:120); % side 'R' (Recieving) and phase 'a' current
vR_a=theta_v*y(11,1:120);
vR_b=theta_v*y(12,1:120);
vR_c=theta_v*y(13,1:120);
% Processing currents of the side "S"
ISa=filter(FF, 1, iS_a); % phase 'a'
ISb=filter(FF, 1, iS_b); % phase 'b'
ISc=filter(FF, 1, iS_c); % phase 'c'
% Processing currents of the side "R"
IRa=filter(FF, 1, iR_a); % phase 'a'
IRb=filter(FF, 1, iR_b); % phase 'b'
IRc=filter(FF, 1, iR_c); % phase 'c'
% Processing voltages of the side "S"
VSa=filter(FF, 1, vS_a); % phase 'a'
VSb=filter(FF, 1, vS_b); % phase 'b'
VSc=filter(FF, 1, vS_c); % phase 'c'
% Processing voltages of the side "R"
VRa=filter(FF, 1, vR_a); % phase 'a'
VRb=filter(FF, 1, vR_b); % phase 'b'
VRc=filter(FF, 1, vR_c); % phase 'c'
% Start of CALCULATIONS FOR FAULT DIRECTION DISCRIMINATION
% Positive-sequence components of the currents and voltages
%S
for k=1:1:60
IS1=(1/3)*(ISa+(a*ISb)+(a^2*ISc))
VS1=(1/3)*(VSa+(a*VSb)+(a^2*VSc))
ZS1=(VS1)./(IS1)
end
%R
for k=1:1:60
IR1=(1/3)*(IRa+(a*IRb)+(a^2*IRc))
VR1=(1/3)*(VRa+(a*VRb)+(a^2*VRc))
ZR1=(VR1)./(IR1)
end
% Incremental positive-sequence currents and voltages
for k=1:1:60
del_IS1=(IS1(k+60)-IS1(k))
del_VS1=(VS1(k+60)-VS1(k))
end
%R
for k=1:1:60
del_IR1=(IR1(k+60)-IR1(k))
del_VR1=(VR1(k+60)-IR1(k))
end
% Incremental positive-sequence impedances
%del_ZS1=(V1-V1pre)/(I1-I1pre)
for k=1:120
del_ZS1=(del_VS1)./(del_IS1)
del_ZR1=(del_VR1)./(del_IR1)
end
% End of CALCULATIONS FOR FAULT DIRECTION DISCRIMINATION
t=y(1,1:120); % time for plotting time functions
figure(5);
% SIDE S - trajectory of incremental positive-sequence impedance with
% marking the starting/ending point. For all of the cases. all simulation
% cases
plot(real(del_ZS1),imag(del_ZS1))
hold on
grid on
plot(real(del_ZS1(1)),imag(del_ZS1(1)),'xr')
hold on
plot(real(del_ZS1(60)),imag(del_ZS1(60)),'kr')
hold on
title('side S - Trajectory of incremental positive-sequence impedance')
legend('del_ZS1','start','end')
xlabel('Real');
ylabel('Imaginary');
ADRIAN JAVIER AREITIO TRILLO
this is the error:
Index exceeds the number of array elements. Index must not exceed 1.
Error in Pr4_S (line 167)
plot(real(del_ZS1(60)),imag(del_ZS1(60)),'kr')

Sign in to comment.

Answers (2)

the cyclist
the cyclist on 24 Nov 2021
Edited: the cyclist on 24 Nov 2021
When you define del_ZS1 in the initial for loop, it is not a vector. It is a single, scalar value.
When you try to do
del_ZS1(60)
you try to access the 60th element, but there is only one element.
Perhaps you intended something more like
for k=1,1:120 % <---- Maybe this was supposed to be just k=1:120 ???
del_ZS1(k)=(del_VS1)./(del_IS1)
del_ZR1(K)=(del_VR1)./(del_IR1)
end
?
  1 Comment
ADRIAN JAVIER AREITIO TRILLO
yeah, i also tried k=1:120 but that dosent seem to solve the issue. It still gives the following error: Index exceeds the number of array elements. Index must not exceed 1.
Error in Pr4_S (line 167)
plot(real(del_ZS1(60)),imag(del_ZS1(60)),'kr')
This is the complete line of code. The problem is located at: plot(real(del_ZS1(1)),imag(del_ZS1(1)),'xr')
% Pr4_S: FAULT DIRECTION DISCRIMINATION with processing signals from the side S (sending)
theta_i=1000; % CT ratio
theta_v=1; % VT ratio
n=20; % number of samples in a single fundamental frequency period
% sampling frequency: 1000 Hz
a=-0.5+i*sqrt(3)/2; % complex operator shifting by 120 deg
% Standard full-cycle FOURIER FILTRATION
%
dT=2*pi/n;
for k=1:n,
alfa=dT/2+(k-1)*dT;
FF(k)=cos(alfa)+sqrt(-1)*sin(alfa);
end;
FF=-2*FF/n;
% READING AND TRANSPOSING *.PL4 FILES
x=readpl452;
size(x);
y=x';
size(y);
% Recalculation to primary quantities
iS_a=theta_i*y(2,1:120); % side 'S' (sending) and phase 'a' current
iS_b=theta_i*y(3,1:120); % side 'S' (sending) and phase 'b' current
iS_c=theta_i*y(4,1:120); % side 'S' (sending) and phase 'a' current
vS_a=theta_v*y(8,1:120);
vS_b=theta_v*y(9,1:120);
vS_c=theta_v*y(10,1:120);
iR_a=theta_i*y(5,1:120); % side 'R' (Recieving) and phase 'a' current
iR_b=theta_i*y(6,1:120); % side 'R' (Recieving) and phase 'b' current
iR_c=theta_i*y(7,1:120); % side 'R' (Recieving) and phase 'a' current
vR_a=theta_v*y(11,1:120);
vR_b=theta_v*y(12,1:120);
vR_c=theta_v*y(13,1:120);
% Processing currents of the side "S"
ISa=filter(FF, 1, iS_a); % phase 'a'
ISb=filter(FF, 1, iS_b); % phase 'b'
ISc=filter(FF, 1, iS_c); % phase 'c'
% Processing currents of the side "R"
IRa=filter(FF, 1, iR_a); % phase 'a'
IRb=filter(FF, 1, iR_b); % phase 'b'
IRc=filter(FF, 1, iR_c); % phase 'c'
% Processing voltages of the side "S"
VSa=filter(FF, 1, vS_a); % phase 'a'
VSb=filter(FF, 1, vS_b); % phase 'b'
VSc=filter(FF, 1, vS_c); % phase 'c'
% Processing voltages of the side "R"
VRa=filter(FF, 1, vR_a); % phase 'a'
VRb=filter(FF, 1, vR_b); % phase 'b'
VRc=filter(FF, 1, vR_c); % phase 'c'
% Start of CALCULATIONS FOR FAULT DIRECTION DISCRIMINATION
% Positive-sequence components of the currents and voltages
%S
for k=1:1:60
IS1=(1/3)*(ISa+(a*ISb)+(a^2*ISc))
VS1=(1/3)*(VSa+(a*VSb)+(a^2*VSc))
ZS1=(VS1)./(IS1)
end
%R
for k=1:1:60
IR1=(1/3)*(IRa+(a*IRb)+(a^2*IRc))
VR1=(1/3)*(VRa+(a*VRb)+(a^2*VRc))
ZR1=(VR1)./(IR1)
end
% Incremental positive-sequence currents and voltages
for k=1:1:60
del_IS1=(IS1(k+60)-IS1(k))
del_VS1=(VS1(k+60)-VS1(k))
end
%R
for k=1:1:60
del_IR1=(IR1(k+60)-IR1(k))
del_VR1=(VR1(k+60)-IR1(k))
end
% Incremental positive-sequence impedances
%del_ZS1=(V1-V1pre)/(I1-I1pre)
for k=1:120
del_ZS1=(del_VS1)./(del_IS1)
del_ZR1=(del_VR1)./(del_IR1)
end
% End of CALCULATIONS FOR FAULT DIRECTION DISCRIMINATION
t=y(1,1:120); % time for plotting time functions
figure(5);
% SIDE S - trajectory of incremental positive-sequence impedance with
% marking the starting/ending point. For all of the cases. all simulation
% cases
plot(real(del_ZS1),imag(del_ZS1))
hold on
grid on
plot(real(del_ZS1(1)),imag(del_ZS1(1)),'xr')
hold on
plot(real(del_ZS1(60)),imag(del_ZS1(60)),'kr')
hold on
title('side S - Trajectory of incremental positive-sequence impedance')
legend('del_ZS1','start','end')
xlabel('Real');
ylabel('Imaginary');

Sign in to comment.


Jan
Jan on 24 Nov 2021
I guess, that the error occurs here:
plot(real(del_ZS1(60)),imag(del_ZS1(60)),'kr')
The message means, that del_ZS1 is a scalar and does not have 60 elements. Use the debugger to check this:
dbstop if error
Type this in the command window and run the code again. Then Matlab stops at the error and you can check the dimensions of the variable in the command window or workspace browser.
  1 Comment
ADRIAN JAVIER AREITIO TRILLO
%the problem seems to be that the variables del_IS1, del_VS1, del_IR1 and del_VR1 arent forming the array needed and are indeed scalar, i dont know why this is happening though, as the K=1:60 seems to not be taking any effect on the equations.
%How can i solve this? Is there any way to change or create a different code from scratch?

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!