"Index exceeds matrix dimensions."

2 Ansichten (letzte 30 Tage)
Eduardo Rojas
Eduardo Rojas am 18 Aug. 2019
Kommentiert: Eduardo Rojas am 20 Aug. 2019
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 Kommentare
Eduardo Rojas
Eduardo Rojas am 18 Aug. 2019
Bearbeitet: per isakson am 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 am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentare
Walter Roberson
Walter Roberson am 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 am 20 Aug. 2019
Ok, thank you
I'm working on the solution

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by