フィルターのクリア

error when the input is zero

4 ビュー (過去 30 日間)
Samer Husam
Samer Husam 2012 年 8 月 27 日
hi all, i am doing a code on MATLAB while the variable input is :
T= Temperature
G= irradiation
but I am getting an error when I have G value equal to zero. the error is :
??? Attempted to access (0); index must be a positive integer or logical.
my code is :
IL=(ISC+(mi)*(T-T1))*(G/G1);
IO1=ISC/(exp((VOC*q)/(NS*A*k*T1))-1);
IO=IO1*((T/T1)^3)*exp((q*EG/(A*k))*((1/T1)-(1/T)));
RS=((NS*A*k*T1/q)*log(((ISC-IM1)/IO1)+1)-VM1)/IM1;
h=IL/1000;
I=0:h:IL;
N=length(I);
V(N)=0; %Error is here on this line!!
for i=1:(N-1)
V(i)=(NS*A*k*T/q)*log(1+(IL-I(i))/IO)-I(i)*RS; %
end
why I am getting this error and how to overcome it ?? please help and advice. thanks

採用された回答

Walter Roberson
Walter Roberson 2012 年 8 月 27 日
When G is 0, then IL comes out 0. Then 0:h:IL is 0 to 0, which has a length (N) of 0. You then attempt to assign to that 0'th element.
What result would you like to get out when the length comes out 0?
Consider using
I = linspace(0, IL, 1001);
instead of the h and I code you hae at the moment.
  1 件のコメント
Samer Husam
Samer Husam 2012 年 8 月 28 日
thanks Mr. Walter, you solution is works... thanks again

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

その他の回答 (1 件)

Babak
Babak 2012 年 8 月 27 日
If you set G = 0, then IL will be evaluated as 0.
When IL = 0, then h = 0 and I = 0:h:IL which is I = [].
And N = length(I) is 0.
Assignment of V(N) is like V(0) is meaningless.
I recommand you not set G = 0. I don't know the reason why it ccan/should be zero.
  1 件のコメント
Samer Husam
Samer Husam 2012 年 8 月 28 日
Mr babak, the reason to use G = zero cuz the irradiation of the sun is equal to zero in the night.
Mr. walter's answer works very well

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

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by