Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0

2 views (last 30 days)
clc;
cp=4186;
Tground=15;
node_i=xlsread('Energy Networks.xlsx','Branches','B6:B35');
node_o=xlsread('Energy Networks.xlsx','Branches','C6:C35');
P=xlsread('Energy Networks.xlsx','Foglio1','O36:O64');
G=xlsread('Energy Networks.xlsx','Foglio1','N36:N65');
L=xlsread('Energy Networks.xlsx','Branches','E6:E35');
nNodes=size(P,1);
nBranches=size(G,1)
Tsupply=95;
TInletCondition=zeros(nNodes,1);
TInletCondition(1)=Tsupply;
TOutletCondition=zeros(nNodes,1);
nBoundaryNodes=0; %initialization
U=xlsread('Energy Networks.xlsx','Branches','M6:M35');
Perimeter=xlsread('Energy Networks.xlsx','Branches','N6:N35');
K=zeros(nNodes,nNodes);
f=zeros(nNodes,1);
A=zeros(nNodes,nBranches);
for i=1:nBranches
in=node_i(i,1);
out=node_o(i,1);
A(in,i)=1;
A(out,i)=-1;
end
for j=1:nBranches
if G(j)<0
A(:,j)=-A(:,j);
end
end
% assembling of K and f
for j=1:nBranches
iInlet=find(A(1:nNodes,j)==1);
iOutlet=find(A(1:nNodes,j)==-1);
K(iOutlet,iInlet)=-G(j)*cp;
end
for i=1:nNodes
jInlet=find(A(i,1:nBranches)==1);
jOutlet=find(A(i,1:nBranches)==-1);
if isempty(jOutlet)==0 && isempty(jInlet)==0
jTotal=[jInlet jOutlet];
K(i,i)=sum(G(jOutlet)*cp+0.5*sum(L(jTotal).*Perimeter(jTotal).*U(jTotal)));
end
for j=1:nBranches
f(i)=f(i)+0.5*abs(A(i,j)).*L(j).*Perimeter(j).*U(j).*Tground;
end
end
%Boundary conditions
for i=1:nNodes
counter=0;
summation=0;
for j=1:nBranches
if A(i,j)~=0
counter=counter+1;
end
end
summation=sum(A(i,:));
if (counter==1) && (summation==-1)
TOutletCondition(i)=1;
end
end
for i=1:nNodes
if TInletCondition(i)>0
K(i,:)=0;
K(i,i)=1;
f(i)=TInletCondition(i);
end
if TOutletCondition(i)>0
joutletBranch=find(A(1,1:nBranches)==-1);
iPreviousnode=find(A(1:nNodes,joutletBranch)==1);
K(i,iPreviousnode)=1-(L(joutletBranch).*U(joutletBranch).*Perimeter(joutletBranch))/(2.*cp.*G(joutletBranch));
K(i,i)=-(1+(L(joutletBranch).*U(joutletBranch).*Perimeter(joutletBranch))/(2.*cp.*G(joutletBranch)));
end
end
Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-0.
Error in ThermalProblem (line 80)
K(i,i)=-(1+(L(joutletBranch).*U(joutletBranch).*Perimeter(joutletBranch))/(2.*cp.*G(joutletBranch)));
Help me please

Answers (1)

Walter Roberson
Walter Roberson on 11 Nov 2020
joutletBranch=find(A(1,1:nBranches)==-1);
What happens if there are no matches? Then joutletBranch would be empty, and you would be computing emptiness, and trying to assign it to the definite scalar position K(i,i)
What happens if there are more than one match? Then you have an / operator between two vectors, and the result is going to depend on the orientation of the vector. row vector / row vector of the same length returns a scalar. column vector / column vector of the same length returns a square matrix. So we need to know the orientation of L(joutletBranch)
MATLAB had an oddity that when you index a vector by a vector, then no matter what the orientation is of the index, the result will have the same orientation of the vector being indexed. So regardless of whether the find() is returning a row or column vector, we need to know the orientation of L to know what shape L(joutletBranch) would have.
L=xlsread('Energy Networks.xlsx','Branches','E6:E35');
and that is a column vector. So L(joutletBranch) is going to return a column vector whenever jOutputBranch is a vector with more than one element, and as mentioned above, column vector / column vector is going to result in a square matrix, and that will not fit into the scalar destination.
  1 Comment
Salvatore Calabrese
Salvatore Calabrese on 11 Nov 2020
thankyou so much!!
joutletBranch=find(A(1,1:nBranches)==-1);
in this line I had to write i instead of 1 like this
joutletBranch=find(A(i,1:nBranches)==-1);
now my code is running whitout errors!

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices 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!