How to define answer value which i got it from ''for'' loop as a variable and use it in the same loop?
3 ビュー (過去 30 日間)
古いコメントを表示
Mohammad Sulaiman Stanekzai
2019 年 7 月 9 日
回答済み: vidhathri bhat
2019 年 7 月 10 日
In the following assignment the last answer is "h2toplam = total + 11698.5"
for sun = 1:1:p ;
if load(sun,1) < pv (sun,1);
h = pv(sun,1)-load (sun,1);
n(sun,1) = double (h); % (PV'den artan Enerji)
deger = sum (n); % (Artan Enerjinin toplam değeri)
total = deger;
h2toplam = total + 11698.56;
i want to use the last answer as a varaible in the same loop in the following assignment. When i use h2toplam instead of h2 in while loop it gives error "Undefined function or variable 'h2toplam' ". Please help me how to define h2toplam as a varaibel.
elseif load(sun,1) > pv (sun,1);
y = load(sun,1) - pv (sun,1); % (Eksik olan Enerjinin De?eri)
v = pemfc(find( pemfc > y(:,1) , 1 ) ); % very important (Eksik olan enerjinin PEMFC'daki belirli aralikta çal??mas?)
x = -v ; % (Eksik olan enerjinin - olarak gösterilmesi)
j(sun,1) = double (x); % (Eksik olan enerjinin PEMFC'daki belirli aralikta çalismasi)
k = 1;
while h2 > 0;
for q = 1:1:e;
h2miktar = (depo(q,1)*(243.71/731));
m(q,1) = double (h2miktar); % (Hidrojen miktari)
h2t = sum (m); % Toplam Hidrojen Miktari
g = h2 + (depo(q,1)*(243.71/731));
h2 = g;
h2v(k) = h2; % (Toplam Hidrojen miktari kac saat icin yeterli oldugunu gosterir)
k = k + 1;
1 件のコメント
Image Analyst
2019 年 7 月 10 日
That code should be OK. You do not need to allocate a variable in advance -- you can create it automatically the first time you use it, as you did. There must be something else wrong with your code. Please post entire code plus entire error message (all the red text).
採用された回答
vidhathri bhat
2019 年 7 月 10 日
Hi,
When you run the loop, on the first iteration if it is going to the else part, then there is no h2toplam variable defined anywhere. Make sure that it is going to the if case for the first iteration or initialize the h2toplam variable with appropriate value before entering the loop.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!