How do you save while loop output in a vector?
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, I'm new to Matlab, I have just recently started learning it and I am quite puzzle about how to save the output of my while loop in a vector so I can plot it later. I think my problem is that I am using two subscripts in the loop ( i and t). The loop works fine and it is giving me the right information, but I cannot save its output. I have searched the web and matlab answers, but nothing seems to work in my case. Anyway, this is the loop:
Hc=[];
Fc=[];
while (round(H(t),1)~=round(H(t-1),1)&&round(F(t),1)~=round(F(t-1),1));
t=t+1;
i=t-1;
H(t)=H(i)+L*(N(i)/(w+N(i)))-H(i)*(0.25-0.75*(F(i)/(N(i)+0.001)));
F(t)=F(i)+H(i)*(0.25-0.75*(F(i)/(N(i)+0.001)))-m*F(i);
N(t)=H(t)+F(t);
Hc(t)=[H(t)];
Fc(t)=[F(t)];
end
I've created Hc and Fc as vectors to store the information from H(t) and F(t), but it does not seem to store any data. Do you have any ideas on how this could be fixed?
Thanks,
Denisse
0 件のコメント
回答 (1 件)
Thorsten
2015 年 9 月 4 日
You don't have to introduce Hc or Fc; the data are already stored in F and H, as in the following example
t = 1;
while t < 10
F(t) = t^2;
t = t+ 1;
end
If Hc and Fc are empty that is probably because the while loop has never been entered, because the expression
(round(H(t),1)~=round(H(t-1),1)&&round(F(t),1)~=round(F(t-1),1));
was never true.
2 件のコメント
Thorsten
2015 年 9 月 8 日
Please post a complete example that we can run to have closer look at what goes wrong.
参考
カテゴリ
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!