Unable to perform two for loops, with a set value from first for loop into second loop

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Kevin Phung
Kevin Phung il 26 Mar 2019
Modificato: Kevin Phung il 26 Mar 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 ./)

Più risposte (2)

Morten Fosstveit
Morten Fosstveit il 26 Mar 2019
Thanks, it was what i wanted. Just needed to add a line for not overwriting previous iteration.
E_comp=E_tot-E_inEl;
end
S(:,r) = E_inEl; %<------
end

MOHAMED-AMINE BABAY
MOHAMED-AMINE BABAY il 4 Ott 2020
Hii , Could you please send me this program

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by