Matrix dimensions must agree. Error in Untitled (line 22) E_net=E_PV-L; ..........​..........​.....error in subtract op,,,,

1 view (last 30 days)
%%(1)Data sources
fileName = 'PVModelingBookDataSource.xls';
sheetName = 'Source 2';
G= xlsread(fileName, sheetName , 'A1:A8761');
T= xlsread(fileName, sheetName , 'B1:B8761');
L= xlsread(fileName, sheetName , 'D1:D8761');
%%(2)System specifications
PV_Wp=2500; % the capacity of the PV array (Watt)
SOCmax= 1400; % battery capacity Wh/day
PV_eff=0.16; % efficiency of the PV module
V_B=12; % voltage of the used battery
Inv_RP=2500; %inverter rated power
DOD=0.8; %allowed depth of charge
Charge_eff=0.8; % charging eff
Alpha= .05; % alpha
Wire_eff= 0.98;
SOCmin=SOCmax*(1-DOD);
%%(3.1) Simulation of the SAPV system
P_Ratio=(PV_Wp *(G/1000))/Inv_RP;
Inv_eff=97.644-(P_Ratio.*1.995)- (0.445./P_Ratio); %5KW
E_PV= ((PV_Wp*(G/1000))-(Alpha*(T-25)))* Wire_eff.*Inv_eff;
E_net=E_PV-L;
SOCi=SOCmax;
SOCf=[];
Deff=[];
Dampf=[];
%%(3.2)
for i=1:length(E_net);
SOC= ED+SOCi;
if (SOC > SOCmax)
Dampi=SOC-SOCmax;
Defi=0;
SOCi=SOCmax;
%%(3.3)
elseif (SOC<SOCmin)
SOCi=SOCmin;
Defi=SOC-SOCmin;
Dampi=0;
%%(3.4)
else
SOCi=SOC;
Defi=0;
Dampi=0;
end
%%(3.5)
SOCf=[SOCf; SOCi];
Deff=[Deff; Defi];
Dampf=[Dampf; Dampi];
end
SOCf;
Deff;
Dampf;
SOC_per=SOCf./SOCmax;
LLP_calculated=abs(sum(Deff))/(sum (L));

Answers (1)

Cris LaPierre
Cris LaPierre on 25 Mar 2023
For the matrix subtraction operation to work, L must either be a scalar, or be the same size as E_PV.
The only way I can reproduce the error on that line is if I make L a different size. Check your raw data. Some of the data may be missing, or may be non-numeric.
G= rand(1,8761);
T= rand(1,8761);
L= rand(1,8760); % <---- I have changed the size to reproduce the error ###################
%%(2)System specifications
PV_Wp=2500; % the capacity of the PV array (Watt)
SOCmax= 1400; % battery capacity Wh/day
PV_eff=0.16; % efficiency of the PV module
V_B=12; % voltage of the used battery
Inv_RP=2500; %inverter rated power
DOD=0.8; %allowed depth of charge
Charge_eff=0.8; % charging eff
Alpha= .05; % alpha
Wire_eff= 0.98;
SOCmin=SOCmax*(1-DOD);
%%(3.1) Simulation of the SAPV system
P_Ratio=(PV_Wp *(G/1000))/Inv_RP;
Inv_eff=97.644-(P_Ratio.*1.995)- (0.445./P_Ratio); %5KW
E_PV= ((PV_Wp*(G/1000))-(Alpha*(T-25)))* Wire_eff.*Inv_eff;
E_net=E_PV-L;
Arrays have incompatible sizes for this operation.
  1 Comment
Stephen23
Stephen23 on 25 Mar 2023
"For the matrix subtraction operation to work, L must either be a scalar, or be the same size as E_PV."
Or have compatible sizes:
rand(3,1,2) - rand(3,5,1) % compatible sizes -> works
ans =
ans(:,:,1) = -0.4983 -0.4474 0.1737 0.0522 -0.4380 -0.1268 -0.1093 0.7476 0.0061 0.1320 -0.0564 -0.1403 -0.0990 -0.2360 -0.3543 ans(:,:,2) = -0.7475 -0.6965 -0.0755 -0.1969 -0.6872 -0.1137 -0.0962 0.7607 0.0193 0.1452 0.5109 0.4270 0.4683 0.3313 0.2130
See:

Sign in to comment.

Categories

Find more on Propulsion and Power Systems in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!