MATLAB Answers

0

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

Morten Fosstveit さんによって質問されました 2019 年 3 月 26 日
最新アクティビティ Morten Fosstveit さんによって 回答されました 2019 年 3 月 26 日
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 件のコメント

サインイン to comment.

2 件の回答

回答者: Kevin Phung
2019 年 3 月 26 日
編集済み: Kevin Phung
2019 年 3 月 26 日
 採用された回答

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 件のコメント

サインイン to comment.


回答者: Morten Fosstveit 2019 年 3 月 26 日

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

  0 件のコメント

サインイン to comment.



Translated by