"Index exceeds matrix dimensions."

2 views (last 30 days)
clear all
clc
nodos=input('Ingresa la cantidad de nodos del sistema\n n = ');
noZ=input('Ingresa la cantidad de lineas del sistema \n NoZ = ');
for i=1:noZ %Ciclo para ingresar los valores de la Z de rama.
ne(i)=input('Número de referencia del nodo emisor = ');
nr(i)=input('Número de referencia del nodo receptor = ');
%clc
fi=2%('Número de filas de la matriz = ');
co=2%2'Número de columnas de la matriz = ');
clc
disp(['Ingresa la matriz de impedancias de la linea #',num2str(i),':'])
for j=1:fi%Filas
for jj=1:co%Columnas
disp(['El elemento (',num2str(j),',',num2str(jj),')'])
Ztramo(j,jj,i)=input('');
end
end
clc
disp(['La matriz de impedancias del tramo #',num2str(i),' es:'])
Ztramo% Muestra Z de tramo con ceros.
disp(['La matriz de admitancias del tramo #',num2str(i),' es:'])
Ytramo(:,:,i)=inv(Ztramo(:,:,i));
Ytramo
ybus=diag(0,(nodos*2)-1);
end
for i=1:noZ %Ciclo para la formación de YBUS
k1=ne(:,:,i);
k2=nr(:,:,i);
ybus(k1,k1)=ybus(k1,k1)+Ytramo(:,:,i);
ybus(k2,k2)=ybus(k2,k2)+Ytramo(:,:,i);
ybus(k1,k2)=-Ytramo(:,:,i);
ybus(k2,k1)=ybus(k1,k2);
end
clc
ybus
  3 Comments
Eduardo Rojas
Eduardo Rojas on 18 Aug 2019
Edited: per isakson on 18 Aug 2019
The full message is: Index exceeds matrix dimensions.
Assignment has more non-singleton rhs dimensions than
non-singleton subscripts
Code:
clear all
clc
nodos=input('Ingresa la cantidad de nodos del sistema\n n = ');
noZ=input('Ingresa la cantidad de lineas del sistema \n NoZ = ');
for i=1:noZ %Ciclo para ingresar los valores de la Z de rama.
ne(i)=input('Número de referencia del nodo emisor = ');
nr(i)=input('Número de referencia del nodo receptor = ');
%clc
fi=2%('Número de filas de la matriz = ');
co=2%2'Número de columnas de la matriz = ');
clc
disp(['Ingresa la matriz de impedancias de la linea #',num2str(i),':'])
for j=1:fi%Filas
for jj=1:co%Columnas
disp(['El elemento (',num2str(j),',',num2str(jj),')'])
Ztramo(j,jj,i)=input('');
end
end
clc
disp(['La matriz de impedancias del tramo #',num2str(i),' es:'])
Ztramo% Muestra Z de tramo con ceros.
disp(['La matriz de admitancias del tramo #',num2str(i),' es:'])
Ytramo(:,:,i)=inv(Ztramo(:,:,i));
Ytramo
ybus=diag(0,(nodos*2)-1);
end
for i=1:noZ %Ciclo para la formación de YBUS
k1=ne(i);
k2=nr(i);
ybus(k1,k1)=ybus(k1,k1)+Ytramo(:,:,i);
ybus(k2,k2)=ybus(k2,k2)+Ytramo(:,:,i);
ybus(k1,k2)=-Ytramo(:,:,i);
ybus(k2,k1)=ybus(k1,k2);
end
clc
ybus
Walter Roberson
Walter Roberson on 18 Aug 2019
What line is the error being shown for?
What are the inputs you are using?
You should post enough that we can reproduce the problem on our systems.

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Aug 2019
Ztramo is an fi by co by noZ matrix.
inv(Ztramo(:,:,i)) is a fi by co matrix if it works at all, which can only happen if fi and co are equal. Therefore
Ytramo(:,:,i)=inv(Ztramo(:,:,i));
makes Ytramo as a fi by co by noZ matrix.
Then in
k1=ne(i);
k2=nr(i);
k1 and k2 are scalars because i is a scalar and indexing by a scalar always gives a scalar.
ybus(k1,k1)=ybus(k1,k1)+Ytramo(:,:,i);
So the left hand size, ybus(k1,k1) is a scalar, and the right hand side of the equation needs to be a scalar. Looking at it, the ybus(k1,k1) part of the addition is a scalar, but Ytramo(:,:,i) we have determined must be fi by co . Adding a scalar to a matrix that is fi by co gives a matrix that is fi by co. Therefore the result of the addition is a matrix that is fi by co, and that is too big to store into the scalar area designated by the left side, ybus(k1,k1)
  3 Comments
Walter Roberson
Walter Roberson on 19 Aug 2019
fi=2%('Número de filas de la matriz = ');
co=2%2'Número de columnas de la matriz = ');
You create a matrix which has fi rows and co columns.
Eduardo Rojas
Eduardo Rojas on 20 Aug 2019
Ok, thank you
I'm working on the solution

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!