# WHY THIS ERROR OCCUR ''??? Subscript indices must either be real positive integers or logicals."" IN 14TH LINE OF MY PROGRAM.PLEASE HELP ME .....THANKING YOU

1 view (last 30 days)
surendar vb on 5 Nov 2012
Answered: Walter Roberson on 2 Apr 2016
clear all;
zdata=[1 2 .025 .1;2 3 .02 .08;3 4 .05 .2;1 4 .04 .16];
n1=zdata(:,1);
nr=zdata(:,2);
r=zdata(:,3);
x=zdata(:,4);
nbr=length(zdata(:,1));
nbus=max(max(n1),max(nr));
z=r+1j*x;
y=ones(nbr,1)./z;
ybus=zeros(nbus,nbus);
for k=1:nbr
if n1(k)>0&&nr(k)>0
ybus(n1(k),nr(k))=ybus(n1(k),nr(k)-y(k));
ybus(nr(k),n1(k))=ybus(n1(k),nr(k));
end
end
for n=1:nbus
for k=1:nbr
if n1(k)==n||nr(k)==n
ybus(n,n)=ybus(n,n)+y(k);
else
end
end
end
ybus

Arthur on 5 Nov 2012
You are trying to retrieve values from ybus using n1 and nr, which are derived from zdata. However, zdata contains values that are not integers. For instance, ybus(.025, 0.2) cannot exist, subscripts have to be integers.
I'm not sure what you are trying to do in this code, but with these values of zdata it will not work.
##### 2 CommentsShowHide 1 older comment
Arthur on 5 Nov 2012
I don't know what a zbus is. But for your code to run, zdata must contain only integers.

Quynh tran on 2 Apr 2016
clear all;
zdata=[1 2 .025 .1;2 3 .02 .08;3 4 .05 .2;1 4 .04 .16];
n1=zdata(:,1);
nr=zdata(:,2);
r=zdata(:,3);
x=zdata(:,4);
nbr=length(zdata(:,1));
nbus=max(max(n1),max(nr));
z=r+1j*x;
y=ones(nbr,1)./z;
ybus=zeros(nbus,nbus);
for k=1:nbr
if n1(k)>0&&nr(k)>0
ybus(n1(k),nr(k))=ybus(n1(k),nr(k)-y(k));
ybus(nr(k),n1(k))=ybus(n1(k),nr(k));
end
end
for n=1:nbus
for k=1:nbr
if n1(k)==n
ybus(n,n)=ybus(n,n)+y(k);
else
if nr(k)==n
ybus(n,n)=ybus(n,n)+y(k); %this row I think should be another formulation
end
end
end
end
Walter Roberson on 2 Apr 2016

Walter Roberson on 2 Apr 2016
zdata=[1 2 .025 .1;2 3 .02 .08;3 4 .05 .2;1 4 .04 .16];
n1=zdata(:,1);
nr=zdata(:,2);
Those lines are fine in themselves. n1 and nr both get assigned values that are strictly non-negative integers, so it is fine to use elements of n1 and nr as indices.
r=zdata(:,3);
x=zdata(:,4);
z=r+1j*x;
Those extract non-integral values, and create z as a vector of complex non-integral numbers.
y=ones(nbr,1)./z;
So y is going to be the reciprocal of complex numbers, and so is going to be complex itself.
ybus(n1(k),nr(k))=ybus(n1(k),nr(k)-y(k));
Here on the right hand side, ybus is being indexed by n1(k) and nr(k)-y(k) . The first of those, n1(k), we have shown will be a positive integer, so that first subscript is fine. The second of those, nr(k)-y(k), we have shown that nr(k) will be an integer but that y(k) will be a complex non-integral value. We can see that nr(k)-y(k) must be a complex result. complex results cannot be used as indices for arrays.
I speculate that the desired line was
ybus(n1(k),nr(k)) = ybus(n1(k),nr(k)) - y(k);
Here, the n1 and nr are both positive integers and can be used as indices. The ybus value is indexed and retrieved and the complex value y(k) is subtracted from that, which is completely valid because the complex value is not being used as an index.