Unable to perform two for loops, with a set value from first for loop into second loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Morten Fosstveit
el 26 de Mzo. de 2019
Respondida: MOHAMED-AMINE BABAY
el 4 de Oct. de 2020
I am trying to calculate E_tot, E_inEl and E_comp for each p_limit (250, 500 and 750) and output a vector of 8760x3, i have limited experiense with matlab and cant seem to figure this out. Is there anyone that could help me? Excel file can be found in attachment.
I am getting this error when running the script.
Unable to perform assignment because the left and right sides have a different number of elements.
Error in test (line 104)
E_tot(E_tot>E_max)=E_max;
[B]=xlsread('Fullyear(Metnom)');
SI_y=B(:,1);
%parameters
n=0.2; %Efficientcy PV
P_outp=1*10^6; %Wp PV
Area=P_outp/(n*max(SI_y)); %Area [m^2] PV
m_h2=55; %kWh/kg H_2
n_comp=0.1; %Energy for compression 10% of total energy used in eletrolysis
n_coff=0.2; %Dynamic range, cut-off @ 20% (AWE)
p_limit=[250:250:750] %Electrolyzer Size [kWh]
h=1:1:8760; %Hours in year [t]
for i=p_limit
p_lim=p_limit*n_coff; %Electrolyzer production cut-off [kWh] @ (20%)
E_min=p_limit*n_coff+p_lim*n_comp;
E_max=p_limit*(1+n_comp);
for ii=h
E=n*SI_y*Area*10^-3; %Power output PV [kWh]
E_tot=E; %Total power [kWh]
E_tot(E_tot<E_min)=0;
E_tot(E_tot>E_max)=E_max;
E_inEl=E-E*n_comp; %Power input electrolyzer [kWh]
E_inEl(E_inEl<p_lim)=0;
E_inEl(E_inEl>p_limit)=p_limit;
E_comp=E_tot-E_inEl; %Power for compression [kWh]
end
end
0 comentarios
Respuesta aceptada
Kevin Phung
el 26 de Mzo. de 2019
Editada: Kevin Phung
el 26 de Mzo. de 2019
The problem is that your Emax is defined as a 1x3 array. So I think you meant to index your p_limit vector.
Heres sort of what you should do, refer to my comments:
for i=1:numel(p_limit) % for each value in p_limit
p_lim=p_limit(i)*n_coff; %index plimit here
E_min=p_limit(i)*n_coff+p_lim*n_comp;
E_max=p_limit(i)*(1+n_comp);
for ii=h % I dont know what h is here
E=n*SI_y*Area*10^-3;
E_tot=E;
E_tot(E_tot<E_min)=0;
E_tot(E_tot>E_max)=E_max;
E_inEl=E-E*n_comp;
E_inEl(E_inEl<p_lim)=0;
E_inEl(E_inEl>p_limit)=p_limit(i); %indexed p_limit
E_comp=E_tot-E_inEl;
end
end
I'm not sure how your second forloop goes, but perhaps you can double check the indexing. Also, if you are multiplying two arrays, be sure to check if you need to do the element wise operator (.* or ./)
0 comentarios
Más respuestas (2)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!