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

조회 수: 5 (최근 30일)
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

답변 (3개)

Arthur
Arthur 2012년 11월 5일
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
surendar vb
surendar vb 2012년 11월 5일
sir im tryin to form a zbus..please help me sir ,same program only i done at my coleg and i got output now its not working :(
Arthur
Arthur 2012년 11월 5일
I don't know what a zbus is. But for your code to run, zdata must contain only integers.

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


Quynh tran
Quynh tran 2016년 4월 2일
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
Walter Roberson 2016년 4월 2일
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.

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by