Matrix dimensions must agree. Error in Untitled (line 22) E_net=E_PV-L; .........................error in subtract op,,,,
1 view (last 30 days)
Show older comments
%%(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));
0 Comments
Answers (1)
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;
1 Comment
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
See:
See Also
Categories
Find more on Propulsion and Power Systems 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!