フィルターのクリア

I have the code below and there is an error which couldn't catch any help please ?

2 ビュー (過去 30 日間)
ABDULLA RAHIL
ABDULLA RAHIL 2016 年 3 月 1 日
編集済み: Jan 2016 年 3 月 1 日
hyd_dem=A/2.3; % each kg require 2.3kw ((54.6kwh/kg))
Ele_consum=B/2.3; %2.3kw/kg ((54.6kwh/kg))
Num_ele=Ele_consum/1500; % 1500 kg/day is rated electrolyser production
Num_ele = round( Num_ele,0); % convert the decimal numbers to integers
hydrogen_excess= Ele_consum-hyd_dem; % excess and deficiency of hydrogen
hydrogen_extra= hyd_dem-Ele_consum;
H2 =max(hydrogen_excess);
F=[0 0];
i=0;
while(i<=365)
i=i+1;
if(hydrogen_excess(i)>=0)
if (F(i)<=H2)
hydrogen_excess(i)=hydrogen_excess(i);
else
hydrogen_excess(i)=0;
end
else
Excess(i)=0;
end
end % [EDITED, Jan, ???]
if(hydrogen_extra(i)>=0)
if (F(i)>=hydrogen_extra(i))
hydrogen_extra(i)=hydrogen_extra(i);
else
hydrogen_extra(i)=F(i);
end
if(hydrogen_excess(i)>0)
F(i+1)=F(i)+hydrogen_excess(i);
elseif(hydrogen_extra(i)>0)
F(i+1)=F(i)-hydrogen_extra(i);
else
F(i+1)=F(i);
end
end
%%%% the error was
((Attempted to access F(6); index out of bounds because numel(F)=2.
Error in Untitled4 (line 17)
if (F(i)<=H2) ))

採用された回答

Image Analyst
Image Analyst 2016 年 3 月 1 日
Somehow i is getting up to 6, but you only defined F as having 2 values, both zero. Make F have at least as many values as the value that you expect i to reach.
  1 件のコメント
ABDULLA RAHIL
ABDULLA RAHIL 2016 年 3 月 1 日
I cant guess the F value since its change between the excess and extra so difficult to if u put any other values still the same error

サインインしてコメントする。

その他の回答 (1 件)

Jan
Jan 2016 年 3 月 1 日
編集済み: Jan 2016 年 3 月 1 日
I've edited the code in the your question and added a standard indentation. Then it gets obvious, that the loop runs without updating F. I assume, that the end marked by [???] is misplaced and should be moved to the end of the code.
Use the auto-indentation to see such problems immediately. Or mark the code in the editor and hit Ctrl-i.
But even if this is the problem, the error message would occur at i==3 already. The message for F(6) is impossible with the shown code. So please post the code, which causes the error to avoid yo confuse the readers.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by