How to code "while" loop for the following problem?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammad Sulaiman Stanekzai
le 14 Juil 2019
Modifié(e) : Image Analyst
le 14 Juil 2019
hello friends. I want to write "while" loop for the follwing problem but it don't give the answer which i want. ii starts from 0. The system which i want is like that.
3.749893 , 3.749893 + ii(0) = ii1
5.217726 , ii1 + 5.217726 = ii2
0.412081 , ii2 + 0.412081 = ii3
0.113385 , ii3 + 0.113385 = ii4
1.27062 , ii4 + 1.27062 = ii5
2.740936 , ii5 + 2.740936 = ii6
2.208374 , ii6 + 2.208374= ii7
so on..
I cant code this proble in while loop.
Thanks in advance.
ii = 0;
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 degeri)
Q = find (n > 0);
answer = n(Q);
WW= answer / 4;
k = 1;
while ii < deger ;
g2 = ii + WW;
ii = g2;
end
end
4 commentaires
KALYAN ACHARJYA
le 14 Juil 2019
Modifié(e) : KALYAN ACHARJYA
le 14 Juil 2019
Sorry, still the question is not clear for me.
Mohammad Sulaiman Stanekzai
le 14 Juil 2019
Modifié(e) : Mohammad Sulaiman Stanekzai
le 14 Juil 2019
Réponse acceptée
KALYAN ACHARJYA
le 14 Juil 2019
Modifié(e) : KALYAN ACHARJYA
le 14 Juil 2019
ww=[3.749893
5.217726
0.412081
0.113385
1.27062
2.740936
2.208374];
% Here considering sample ww only
count=1;
result=0;
while count<=length(ww)
result=ww(count)+result;
count=count+1;
end
disp(result);
12 commentaires
Mohammad Sulaiman Stanekzai
le 14 Juil 2019
Modifié(e) : Image Analyst
le 14 Juil 2019
Image Analyst
le 14 Juil 2019
Modifié(e) : Image Analyst
le 14 Juil 2019
How about
ii = 11698.56
index = 2;
while index <= length(Y)
ii(index) = ii(index - 1) - Y(index - 1)
index = index + 1;
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!